Class: Assembly::Images

Inherits:
Object
  • Object
show all
Defined in:
lib/assembly-image/images.rb

Overview

The Images class contains methods to operate on multiple images in batch.

Class Method Summary collapse

Class Method Details

.batch_add_exif_profile_description(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')

Parameters:

  • source (String)

    path full path to the directory containing TIFFs

  • profile_name (String)

    profile name to be added, current options are ‘Adobe RBG 1998’,‘Dot Gain 20%’,‘sRGB IEC61966-2.1’

  • params (Hash) (defaults to: {})

    Optional parameters specified as a hash, using symbols for options:

    • :force => if set to true, force overwrite a color profile description even if it already exists (default: false)

    • :recusrive => if set to true, directories will be searched recursively for TIFFs from the source specified, false searches the top level only (default: false)

    • :extension => defines the types of files that will be processed (default ‘.tif’)



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/assembly-image/images.rb', line 31

def self.batch_add_exif_profile_description(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')

Parameters:

  • source (String)

    path full path to the directory containing TIFFs to be converted to JP2

  • params (Hash) (defaults to: {})

    Optional parameters specified as a hash, using symbols for options:

    • :output=>‘/full/path_to_jp2’ # specifies full path to folder where jp2s will be created (default: jp2 subdirectory from source path)

    • :overwrite => if set to false, an existing JP2 file with the same name won’t be overwritten (default: false)

    • :recursive => if set to true, directories will be searched recursively for TIFFs from the source specified, false searches the top level only (default: false)

    • :extension => defines the types of files that will be processed (default ‘.tif’)



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/assembly-image/images.rb', line 66

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
        derivative_img=source_img.create_jp2(:overwrite=>overwrite,:output=>output_img)
        logger.debug "Generated jp2 for #{File.basename(file)}"
      rescue Exception => e
        logger.debug "** Error for #{File.basename(file)}: #{e.message}"
      end
    end
    'Complete'

end

.loggerObject



7
8
9
# File 'lib/assembly-image/images.rb', line 7

def self.logger
  @logger ||= Logger.new(STDERR)
end

.logger=(logger) ⇒ Object



11
12
13
# File 'lib/assembly-image/images.rb', line 11

def self.logger= logger
  @logger = logger
end