Class: Assembly::Images
- Inherits:
-
Object
- Object
- Assembly::Images
- Defined in:
- lib/assembly-image/images.rb
Overview
The Images class contains methods to operate on multiple images in batch.
Class Attribute Summary collapse
Class Method Summary collapse
-
.batch_add_exif_profile_descr(source, profile_name, params = {}) ⇒ Object
Pass in a source path and have exif color profile descriptions added to all images contained.
-
.batch_generate_jp2(source, params = {}) ⇒ Object
Pass in a source path and get JP2s generate for each tiff that is in the source path.
Class Attribute Details
.logger ⇒ Object
7 8 9 |
# File 'lib/assembly-image/images.rb', line 7 def self.logger @logger ||= Logger.new(STDERR) end |
Class Method Details
.batch_add_exif_profile_descr(source, profile_name, params = {}) ⇒ Object
Pass in a source path and have exif color profile descriptions added to all images contained. This is useful if your source TIFFs do not have color profile descriptions in the EXIF data, but you know what it should be. This will allow the images to pass the validty check and have JP2s created successfully.
Note you will need full read/write access to the source path so that new EXIF data can be saved.
Example:
Assembly::Images.batch_add_exif_profile_description('/full_path_to_tifs','Adobe RGB 1998')
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/assembly-image/images.rb', line 33 def self.batch_add_exif_profile_descr(source, profile_name, params = {}) extension = params[:extension] || 'tif' recursive = params[:recursive] || false force = params[:force] || false raise 'Input path does not exist' unless File.directory?(source) logger.debug "Source: #{source}" # iterate over input directory looking for tifs pattern = recursive ? "**/*.#{extension}" : "*.#{extension}*" Dir.glob(File.join(source, pattern)).each do |file| img = Assembly::Image.new(file) logger.debug "Processing #{file}" img.add_exif_profile_description(profile_name, force) end 'Complete' end |
.batch_generate_jp2(source, params = {}) ⇒ Object
Pass in a source path and get JP2s generate for each tiff that is in the source path
If not passed in, the destination will be a “jp2” subfolder within the source folder. Note you will need read access to the source path, and write access to the destination path.
Example:
Assembly::Images.batch_generate_jp2('/full_path_to_tifs')
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/assembly-image/images.rb', line 73 def self.batch_generate_jp2(source, params = {}) raise 'Input path does not exist' unless File.directory?(source) output = params[:output] || File.join(source, 'jp2') # default output directgory is jp2 sub-directory from source extension = params[:extension] || 'tif' overwrite = params[:overwrite] || false recursive = params[:recursive] || false Dir.mkdir(output) unless File.directory?(output) # attemp to make output directory raise 'Output path does not exist or could not be created' unless File.directory?(output) logger.debug "Source: #{source}" logger.debug "Destination: #{output}" pattern = recursive ? "**/*.#{extension}" : "*.#{extension}*" # iterate over input directory looking for tifs Dir.glob(File.join(source, pattern)).each do |file| source_img = Assembly::Image.new(file) output_img = File.join(output, File.basename(file, File.extname(file)) + '.jp2') # output image gets same file name as source, but with a jp2 extension and in the correct output directory begin source_img.create_jp2(overwrite: overwrite, output: output_img) logger.debug "Generated jp2 for #{File.basename(file)}" rescue StandardError => e logger.debug "** Error for #{File.basename(file)}: #{e.}" end end 'Complete' end |