Class: IiifPrint::JP2DerivativeService
- Inherits:
-
BaseDerivativeService
- Object
- BaseDerivativeService
- IiifPrint::JP2DerivativeService
- Defined in:
- lib/iiif_print/jp2_derivative_service.rb
Constant Summary collapse
- CMD_GRAY =
OpenJPEG 2000 Command to make NDNP-compliant grayscale JP2:
'opj_compress -i %<source_file>s -o %<out_file>s ' \ '-d 0,0 -b 64,64 -n 6 -p RLCP -t 1024,1024 -I -M 1 ' \ '-r 64,53.821,45.249,40,32,26.911,22.630,20,16,14.286,' \ '11.364,10,8,6.667,5.556,4.762,4,3.333,2.857,2.500,2,' \ '1.667,1.429,1.190,1'.freeze
- CMD_COLOR =
OpenJPEG 2000 Command to make RGB JP2:
'opj_compress -i %<source_file>s -o %<out_file>s ' \ '-d 0,0 -b 64,64 -n 6 -p RPCL -t 1024,1024 -I -M 1 '\ '-r 2.4,1.48331273,.91673033,.56657224,.35016049,.21641118,' \ '.13374944,.0944,.08266171'.freeze
- CMD_1X =
OpenJPEG 1.x command replacement for 2.x opj_compress, takes same options;
this is necessary on Ubuntu Trusty (e.g. Travis CI) 'image_to_j2k'.freeze
Instance Attribute Summary collapse
-
#file_set ⇒ Object
readonly
Returns the value of attribute file_set.
Attributes inherited from BaseDerivativeService
Instance Method Summary collapse
- #create_derivatives(filename) ⇒ Object
-
#initialize(file_set) ⇒ JP2DerivativeService
constructor
A new instance of JP2DerivativeService.
Methods inherited from BaseDerivativeService
#cleanup_derivatives, #convert_cmd, #derivative_path_factory, #identify, #im_convert, #jp2_convert, #jp2_to_intermediate, #load_destpath, #mime_type, #mime_type_for, #one_bit?, #prepare_path, #use_color?, #valid?
Constructor Details
#initialize(file_set) ⇒ JP2DerivativeService
Returns a new instance of JP2DerivativeService.
28 29 30 31 32 33 |
# File 'lib/iiif_print/jp2_derivative_service.rb', line 28 def initialize(file_set) # cached result string for imagemagick `identify` command @command = nil @unlink_after_creation = [] super(file_set) end |
Instance Attribute Details
#file_set ⇒ Object (readonly)
Returns the value of attribute file_set.
25 26 27 |
# File 'lib/iiif_print/jp2_derivative_service.rb', line 25 def file_set @file_set end |
Instance Method Details
#create_derivatives(filename) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/iiif_print/jp2_derivative_service.rb', line 35 def create_derivatives(filename) # Base class takes care of loading @source_path, @dest_path super(filename) # no creation if jp2 master => deemed unnecessary/duplicative return if mime_type == 'image/jp2' # if we have a non-TIFF source, or a 1-bit monochrome source, we need # to make a NetPBM-based intermediate (temporary) file for OpenJPEG # to consume. needs_intermediate = !tiff_source? || one_bit? # We use either intermediate temp file, or temp symlink (to work # around OpenJPEG 2000 file naming quirk). needs_intermediate ? make_intermediate_source : make_symlink # Get OpenJPEG command, rendered with source, destination, appropriate # to either color or grayscale source render_cmd = opj_command # Run the generated command to make derivative file at @dest_path data = `#{render_cmd}` # Create Hyrax::FileMetadata object for the derivatives (if Valkyrie) IiifPrint.copy_derivatives_from_data_store(stream: data, directives: { url: file_set.id.to_s, container: 'service_file', mime_type: mime_type_for(target_extension) }) # Clean up any intermediate files or symlinks used during creation cleanup_intermediate end |