Module: Hydra::Derivatives

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern
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/extract_metadata.rb,
lib/hydra/derivatives/shell_based_processor.rb

Defined Under Namespace

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configObject



21
22
23
# File 'lib/hydra/derivatives.rb', line 21

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

.reset_config!Object



25
26
27
# File 'lib/hydra/derivatives.rb', line 25

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

Instance Method Details

#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.



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/hydra/derivatives.rb', line 47

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

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

Create derivatives from a datastream according to transformation directives

Examples:

This will create content_thumb

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

Specify the dsid for the output datastream

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

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

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

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

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

Parameters:

  • datastream_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)



79
80
81
82
# File 'lib/hydra/derivatives.rb', line 79

def transform_datastream(datastream_name, transform_directives, opts={})
  processor = opts[:processor] ? opts[:processor] : :image
  "Hydra::Derivatives::#{processor.to_s.classify}".constantize.new(self, datastream_name, transform_directives).process
end