Class: Riiif::KakaduTransformer

Inherits:
AbstractTransformer show all
Defined in:
app/transformers/riiif/kakadu_transformer.rb

Overview

Transforms an image using Kakadu

Instance Attribute Summary

Attributes inherited from AbstractTransformer

#image_info, #path, #transformation

Instance Method Summary collapse

Methods inherited from AbstractTransformer

#command_builder, #initialize, transform

Constructor Details

This class inherits a constructor from Riiif::AbstractTransformer

Instance Method Details

#command_factoryObject



4
5
6
# File 'app/transformers/riiif/kakadu_transformer.rb', line 4

def command_factory
  KakaduCommandFactory
end

#post_process(intermediate_file, reduction_factor) ⇒ Object

The data we get back from kdu_expand is a bmp and we need to change it to the requested format by calling Imagemagick.



23
24
25
26
27
28
29
30
31
# File 'app/transformers/riiif/kakadu_transformer.rb', line 23

def post_process(intermediate_file, reduction_factor)
  # Calculate a new set of transforms with respect to reduction_factor
  transformation = if reduction_factor
                     reduce(without_crop, reduction_factor)
                   else
                     without_crop
                   end
  Riiif::File.new(intermediate_file).extract(transformation, image_info)
end

#transformObject



8
9
10
11
12
13
# File 'app/transformers/riiif/kakadu_transformer.rb', line 8

def transform
  with_tempfile do |file_name|
    execute(command_builder.command(file_name))
    post_process(file_name, command_builder.reduction_factor)
  end
end

#with_tempfileObject



15
16
17
18
19
# File 'app/transformers/riiif/kakadu_transformer.rb', line 15

def with_tempfile
  Tempfile.open(['riiif-intermediate', '.bmp']) do |f|
    yield f.path
  end
end