Class: Assembly::Image
- Inherits:
-
Object
- Object
- Assembly::Image
- Includes:
- ObjectFileable
- Defined in:
- lib/assembly-image/image.rb,
lib/assembly-image/version.rb
Overview
Main Image class
Constant Summary collapse
- VERSION =
Project version number
'1.7.7'
Instance Attribute Summary collapse
-
#tmp_path ⇒ Object
stores the path to the tmp file generated during the JP2 creation process.
Instance Method Summary collapse
-
#add_exif_profile_description(profile_name, force = false) ⇒ Object
Add an exif color profile descriptions to the image.
-
#create_jp2(params = {}) ⇒ Assembly::Image
Create a JP2 file for the current image.
-
#dpg_jp2_filename ⇒ string
Returns the full DPG equivalent jp2 path and filename that would match with the given image.
-
#height ⇒ integer
Get the image height from exif data.
-
#jp2_filename ⇒ string
Returns the full default jp2 path and filename that will be created from the given image.
-
#profile ⇒ string
Get the image color profile.
-
#valid? ⇒ boolean
Examines the input image for validity.
-
#width ⇒ integer
Get the image width from exif data Example: source_img=Assembly::Image.new(‘/input/path_to_file.tif’) puts source_img.width # gives 100.
Instance Attribute Details
#tmp_path ⇒ Object
stores the path to the tmp file generated during the JP2 creation process
15 16 17 |
# File 'lib/assembly-image/image.rb', line 15 def tmp_path @tmp_path end |
Instance Method Details
#add_exif_profile_description(profile_name, force = false) ⇒ Object
Add an exif color profile descriptions to the image. 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 validaty 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:
source_img=Assembly::Image.new('/input/path_to_file.tif')
source_img.add_exif_profile_description('Adobe RGB 1998')
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/assembly-image/image.rb', line 82 def add_exif_profile_description(profile_name, force = false) if profile.nil? || force input_profile = profile_name.gsub(/[^[:alnum:]]/, '') # remove all non alpha-numeric characters, so we can get to a filename path_to_profiles = File.join(Assembly::PATH_TO_IMAGE_GEM, 'profiles') input_profile_file = File.join(path_to_profiles, "#{input_profile}.icc") command = "exiftool '-icc_profile<=#{input_profile_file}' #{path}" result = `#{command} 2>&1` raise "profile addition command failed: #{command} with result #{result}" unless $CHILD_STATUS.success? end rescue StandardError => e puts "** Error for #{filename}: #{e.}" end |
#create_jp2(params = {}) ⇒ Assembly::Image
Create a JP2 file for the current image. Important note: this will not work for multipage TIFFs.
Example:
source_img=Assembly::Image.new('/input/path_to_file.tif')
derivative_img=source_img.create_jp2(:overwrite=>true)
puts derivative_img.mimetype # 'image/jp2'
puts derivative_image.path # '/input/path_to_file.jp2'
rubocop:disable Metrics/CyclomaticComplexity:
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/assembly-image/image.rb', line 132 def create_jp2(params = {}) output = params[:output] || jp2_filename create_jp2_checks(output: output, overwrite: params[:overwrite]) # Using instance variable so that can check in tests. @tmp_path = make_tmp_tiff(tmp_folder: params[:tmp_folder]) jp2_command = jp2_create_command(source_path: @tmp_path, output: output) result = `#{jp2_command}` raise "JP2 creation command failed: #{jp2_command} with result #{result}" unless $CHILD_STATUS.success? File.delete(@tmp_path) unless @tmp_path.nil? || params[:preserve_tmp_source] # create output response object, which is an Assembly::Image type object Assembly::Image.new(output) end |
#dpg_jp2_filename ⇒ string
Returns the full DPG equivalent jp2 path and filename that would match with the given image
Example:
source_img=Assembly::Image.new('/input/path_to_file.tif')
puts source_img.jp2_filename # gives /input/path_to_file.jp2
111 112 113 |
# File 'lib/assembly-image/image.rb', line 111 def dpg_jp2_filename jp2_filename.gsub('_00_', '_05_') end |
#height ⇒ integer
Get the image height from exif data
Example:
source_img=Assembly::Image.new('/input/path_to_file.tif')
puts source_img.height # gives 100
45 46 47 |
# File 'lib/assembly-image/image.rb', line 45 def height exif.imageheight end |
#jp2_filename ⇒ string
Returns the full default jp2 path and filename that will be created from the given image
Example:
source_img=Assembly::Image.new('/input/path_to_file.tif')
puts source_img.jp2_filename # gives /input/path_to_file.jp2
101 102 103 |
# File 'lib/assembly-image/image.rb', line 101 def jp2_filename File.extname(@path).empty? ? "#{@path}.jp2" : @path.gsub(File.extname(@path), '.jp2') end |
#profile ⇒ string
Get the image color profile
Example:
source_img=Assembly::Image.new('/input/path_to_file.tif')
puts source_img.profile # gives 'Adobe RGB 1998'
35 36 37 |
# File 'lib/assembly-image/image.rb', line 35 def profile exif.nil? ? nil : exif['profiledescription'] end |
#valid? ⇒ boolean
Examines the input image for validity. Used to determine if image is correct and if JP2 generation is likely to succeed.
This method is automatically called before you create a jp2 but it can be called separately earlier as a sanity check.
Example:
source_img=Assembly::ObjectFile.new('/input/path_to_file.tif')
puts source_img.valid? # gives true
25 26 27 |
# File 'lib/assembly-image/image.rb', line 25 def valid? valid_image? # behavior is defined in assembly-objectfile gem end |
#width ⇒ integer
Get the image width from exif data Example:
source_img=Assembly::Image.new('/input/path_to_file.tif')
puts source_img.width # gives 100
54 55 56 |
# File 'lib/assembly-image/image.rb', line 54 def width exif.imagewidth end |