Class: Hydra::Derivatives::Processors::Image

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

Direct Known Subclasses

RawImage

Instance Attribute Summary

Attributes inherited from Processor

#directives, #output_file_service, #source_path

Instance Method Summary collapse

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

#processObject



7
8
9
# File 'lib/hydra/derivatives/processors/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/processors/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/processors/image.rb', line 19

def process_without_timeout
  format = directives.fetch(:format)
  name = directives.fetch(:label, format)
  destination_name = output_filename_for(name)
  size = directives.fetch(:size, nil)
  quality = directives.fetch(:quality, nil)
  create_resized_image(destination_name, size, format, quality)
end