Class: Hydra::Derivatives::Processors::Jpeg2kImage
- Includes:
- ShellBasedProcessor
- Defined in:
- lib/hydra/derivatives/processors/jpeg2k_image.rb
Constant Summary
Constants included from ShellBasedProcessor
ShellBasedProcessor::BLOCK_SIZE
Instance Attribute Summary
Attributes inherited from Processor
#directives, #output_file_service, #source_path
Instance Method Summary collapse
Methods included from ShellBasedProcessor
Methods inherited from Processor
#initialize, #output_file, #output_file_id, #output_filename_for
Constructor Details
This class inherits a constructor from Hydra::Derivatives::Processors::Processor
Instance Method Details
#encode_file(recipe, opts = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hydra/derivatives/processors/jpeg2k_image.rb', line 25 def encode_file(recipe, opts={}) output_file = self.class.tmp_file('.jp2') if opts[:file_path] self.class.encode(opts[:file_path], recipe, output_file) else Hydra::Derivatives::TempfileService.create(source_file) do |f| self.class.encode(f.path, recipe, output_file) end end output_file_service.call(File.open(output_file, 'rb'), directives) File.unlink(output_file) end |
#process ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hydra/derivatives/processors/jpeg2k_image.rb', line 9 def process image = MiniMagick::Image.open(source_path) quality = image['%[channels]'] == 'gray' ? 'gray' : 'color' name = directives.fetch(:label) long_dim = self.class.long_dim(image) file_path = self.class.tmp_file('.tif') to_srgb = directives.fetch(:to_srgb, true) if directives[:resize] || to_srgb preprocess(image, resize: directives[:resize], to_srgb: to_srgb, src_quality: quality) end image.write file_path recipe = self.class.kdu_compress_recipe(directives, quality, long_dim) encode_file(recipe, file_path: file_path) File.unlink(file_path) unless file_path.nil? end |