Class: Assembly::Image::Jp2Creator

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

Overview

Creates jp2 derivatives

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image, overwrite: false, output: image.jp2_filename, tmp_folder: Dir.tmpdir) ⇒ Jp2Creator

Returns a new instance of Jp2Creator.



31
32
33
34
35
36
# File 'lib/assembly/image/jp2_creator.rb', line 31

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

#imageObject (readonly)

Returns the value of attribute image.



38
39
40
# File 'lib/assembly/image/jp2_creator.rb', line 38

def image
  @image
end

#output_pathObject (readonly)

Returns the value of attribute output_path.



38
39
40
# File 'lib/assembly/image/jp2_creator.rb', line 38

def output_path
  @output_path
end

#tmp_folderObject (readonly)

Returns the value of attribute tmp_folder.



38
39
40
# File 'lib/assembly/image/jp2_creator.rb', line 38

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'

Parameters:

  • the (Assembly::Image)

    image file

  • output (String)

    path to the output JP2 file (default: mirrors the source file name and path, but with a .jp2 extension)

  • overwrite (Boolean)

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

  • tmp_folder (Dir)

    the temporary folder to use when creating the jp2 (default: ‘/tmp’); also used by imagemagick

Returns:



27
28
29
# File 'lib/assembly/image/jp2_creator.rb', line 27

def self.create(image, **args)
  new(image, **args).create
end

Instance Method Details

#createAssembly::Image

Returns object containing the generated JP2 file.

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/assembly/image/jp2_creator.rb', line 43

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