Module: Dragonfly::GeometryBridge

Defined in:
lib/dragonfly/geometry_bridge.rb

Overview

Translates legacy ImageMagick geometry strings (e.g. "300x300#c",
"300x300^", "640x>") into libvips/Dragonfly option hashes so
historical cached URLs continue to render after the move to libvips.

Class Method Summary collapse

Class Method Details

.translate(geometry, opts) ⇒ Array(String, Hash)

Converts an ImageMagick fill geometry into libvips crop options.

Logic Details

The application emitted caret geometry only for square video-card
thumbnails, then replaced it with #c. Mapping both forms to a centred
crop preserves that fill-the-card intent for historical signed URLs.

Parameters:

  • geometry (String, Object)

    geometry value from a Dragonfly job URL

  • opts (Hash)

    processor options to copy and augment

Options Hash (opts):

  • :thumbnail_options (Hash)

    existing libvips thumbnail options

Returns:

  • (Array(String, Hash))

    compatible geometry and processor options



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dragonfly/geometry_bridge.rb', line 33

def translate(geometry, opts)
  return [geometry, opts] unless geometry.is_a?(String)

  match = geometry.match(/\A(?<dims>\d*x\d*)(?:#[A-Za-z]*|\^)\z/)
  return [geometry, opts] unless match

  new_opts = opts.dup
  thumbnail_options = new_opts.fetch(:thumbnail_options, {}).dup
  thumbnail_options[:crop] ||= :centre
  new_opts[:thumbnail_options] = thumbnail_options

  [match[:dims], new_opts]
end