Module: Hydra::Derivatives

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern, Deprecation
Defined in:
lib/hydra/derivatives.rb,
lib/hydra/derivatives/audio.rb,
lib/hydra/derivatives/image.rb,
lib/hydra/derivatives/video.rb,
lib/hydra/derivatives/config.rb,
lib/hydra/derivatives/ffmpeg.rb,
lib/hydra/derivatives/logger.rb,
lib/hydra/derivatives/document.rb,
lib/hydra/derivatives/processor.rb,
lib/hydra/derivatives/jpeg2k_image.rb,
lib/hydra/derivatives/video/processor.rb,
lib/hydra/derivatives/extract_metadata.rb,
lib/hydra/derivatives/tempfile_service.rb,
lib/hydra/derivatives/shell_based_processor.rb

Defined Under Namespace

Modules: ClassMethods, ExtractMetadata, Ffmpeg, ShellBasedProcessor, Video Classes: Audio, Config, Document, Image, Jpeg2kImage, Logger, Processor, TempfileService, TimeoutError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configObject



27
28
29
# File 'lib/hydra/derivatives.rb', line 27

def self.config
  @config ||= reset_config!
end

.reset_config!Object



31
32
33
# File 'lib/hydra/derivatives.rb', line 31

def self.reset_config!
  @config = Config.new
end

Instance Method Details

#constantize_processor(processor) ⇒ Object



99
100
101
102
103
# File 'lib/hydra/derivatives.rb', line 99

def constantize_processor(processor)
  "Hydra::Derivatives::#{processor.classify}".constantize
rescue NameError
  processor.classify.constantize
end

#create_derivativesObject

Runs all of the transformations immediately. You may want to run this job in the background as it may take a long time.



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/hydra/derivatives.rb', line 53

def create_derivatives
  if transformation_schemes.present?
    transformation_schemes.each do |transform_scheme|
      if transform_scheme.instance_of?(Proc)
        transform_scheme.call(self)
      else
        send(transform_scheme)
      end
    end
  else
    logger.warn "`create_derivatives' was called on an instance of #{self.class}, but no derivatives have been requested"
  end
end

#processor_class(processor) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/hydra/derivatives.rb', line 90

def processor_class(processor)
  case processor
    when :video
      Hydra::Derivatives::Video::Processor
    else
      constantize_processor(processor.to_s)
    end
end

#transform_datastream(file_name, transform_directives, opts = {}) ⇒ Object



105
106
107
# File 'lib/hydra/derivatives.rb', line 105

def transform_datastream(file_name, transform_directives, opts={})
  transform_file(file_name, transform_directives, opts={})
end

#transform_file(file_name, transform_directives, opts = {}) ⇒ Object

Create derivatives from a file according to transformation directives

Examples:

This will create content_thumb

transform_file :content, { :thumb => "100x100>" }

Specify the dsid for the output file

transform_file :content, { :thumb => {size: "200x300>", datastream: 'thumbnail'} }

Create multiple derivatives with one set of directives. This will create content_thumb and content_medium

transform_file :content, { :medium => "300x300>", :thumb => "100x100>" }

Specify which processor you want to use (defaults to :image)

transform_file :content, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
transform_file :content, { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processor: :video

Parameters:

  • file_name
  • transform_directives (Hash)
    • each key corresponds to a desired derivative. Associated values vary according to processor being used.

  • opts (Hash) (defaults to: {})

    for specifying things like choice of :processor (processor defaults to :image)



85
86
87
88
# File 'lib/hydra/derivatives.rb', line 85

def transform_file(file_name, transform_directives, opts={})
  processor = processor_class(opts[:processor] || :image)
  processor.new(self, file_name, transform_directives).process
end