Class: Assembly::Image::Jp2Creator
- Inherits:
-
Object
- Object
- Assembly::Image::Jp2Creator
- Defined in:
- lib/assembly/image/jp2_creator.rb
Overview
Creates jp2 derivatives
Instance Attribute Summary collapse
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#output_path ⇒ Object
readonly
Returns the value of attribute output_path.
-
#tmp_folder ⇒ Object
readonly
Returns the value of attribute tmp_folder.
Class Method Summary collapse
-
.create(image, **args) ⇒ Assembly::Image
Create a JP2 file for the current image.
Instance Method Summary collapse
-
#create ⇒ Assembly::Image
Object containing the generated JP2 file.
-
#initialize(image, overwrite: false, output: image.jp2_filename, tmp_folder: Dir.tmpdir) ⇒ Jp2Creator
constructor
A new instance of Jp2Creator.
Constructor Details
#initialize(image, overwrite: false, output: image.jp2_filename, tmp_folder: Dir.tmpdir) ⇒ Jp2Creator
Returns a new instance of Jp2Creator.
32 33 34 35 36 37 |
# File 'lib/assembly/image/jp2_creator.rb', line 32 def initialize(image, overwrite: false, output: image.jp2_filename, tmp_folder: Dir.tmpdir) @image = image @output_path = output @tmp_folder = tmp_folder @overwrite = overwrite end |
Instance Attribute Details
#image ⇒ Object (readonly)
Returns the value of attribute image.
39 40 41 |
# File 'lib/assembly/image/jp2_creator.rb', line 39 def image @image end |
#output_path ⇒ Object (readonly)
Returns the value of attribute output_path.
39 40 41 |
# File 'lib/assembly/image/jp2_creator.rb', line 39 def output_path @output_path end |
#tmp_folder ⇒ Object (readonly)
Returns the value of attribute tmp_folder.
39 40 41 |
# File 'lib/assembly/image/jp2_creator.rb', line 39 def tmp_folder @tmp_folder end |
Class Method Details
.create(image, **args) ⇒ 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'
28 29 30 |
# File 'lib/assembly/image/jp2_creator.rb', line 28 def self.create(image, **args) new(image, **args).create end |
Instance Method Details
#create ⇒ Assembly::Image
Returns object containing the generated JP2 file.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/assembly/image/jp2_creator.rb', line 44 def create create_jp2_checks Dir.mktmpdir('assembly-image', tmp_folder) do |tmp_tiff_dir| tmp_tiff_path = File.join(tmp_tiff_dir, 'temp.tif') # KDUcompress doesn’t support arbitrary image types, so we make a temporary tiff make_tmp_tiff(tmp_tiff_path) make_jp2(tmp_tiff_path) end # create output response object, which is an Assembly::Image type object Image.new(output_path) end |