Module: DerivedImages::Dsl

Included in:
Manifest
Defined in:
lib/derived_images/dsl.rb

Overview

Note:

An image format conversions can be automatically inferred from the ‘target` file extension in these methods.

Use these DSL functions in your ‘config/derived_images.rb` file to define images to derive.

Instance Method Summary collapse

Instance Method Details

#derive(target, from:) {|pipeline| ... } ⇒ ManifestEntry

Derive one image from another, with full customization abilities.

Parameters:

  • target (String)

    The relative file name of the target (derived) image

  • from (String)

    The relative file name of the source image. Must be in one of the configured ‘image_paths`

Yield Parameters:

  • pipeline (ImageProcessing::Chainable)

    The pipeline you can use to further customize the transformation

Returns:



25
26
27
28
29
# File 'lib/derived_images/dsl.rb', line 25

def derive(target, from:, &block)
  entry = ManifestEntry.new(from, target)
  entry.pipeline = yield(entry.pipeline) if block
  add_entry(entry)
end

#resize(target, from:, width:, height:) ⇒ ManifestEntry

Resize an image, preserving its aspect ratio.

Parameters:

  • target (String)

    The relative file name of the target (derived) image

  • from (String)

    The relative file name of the source image. Must be in one of the configured ‘image_paths`

  • width (Integer)

    The max width of the derived image

  • height (Integer)

    The max height of the derived image

Returns:



15
16
17
# File 'lib/derived_images/dsl.rb', line 15

def resize(target, from:, width:, height:)
  derive(target, from: from) { _1.resize_to_limit(width, height) }
end