Class: Hydra::Derivatives::Image

Inherits:
Processor show all
Defined in:
lib/hydra/derivatives/image.rb

Instance Attribute Summary

Attributes inherited from Processor

#directives, #object, #source_name

Instance Method Summary collapse

Methods inherited from Processor

#initialize, #output_file, #output_file_id, #source_file

Constructor Details

This class inherits a constructor from Hydra::Derivatives::Processor

Instance Method Details

#processObject



7
8
9
# File 'lib/hydra/derivatives/image.rb', line 7

def process
  timeout ? process_with_timeout : process_without_timeout
end

#process_with_timeoutObject



11
12
13
14
15
16
17
# File 'lib/hydra/derivatives/image.rb', line 11

def process_with_timeout
  status = Timeout::timeout(timeout) do
    process_without_timeout
  end
rescue Timeout::Error => ex
  raise Hydra::Derivatives::TimeoutError, "Unable to process image derivative\nThe command took longer than #{timeout} seconds to execute"
end

#process_without_timeoutObject



19
20
21
22
23
24
25
26
# File 'lib/hydra/derivatives/image.rb', line 19

def process_without_timeout
  directives.each do |name, args|
    opts = args.kind_of?(Hash) ? args : {size: args}
    format = opts.fetch(:format, 'png')
    output_file_name = opts.fetch(:datastream, output_file_id(name))
    create_resized_image(output_file(output_file_name), opts[:size], format)
  end
end