Class: ImgproxyRails::Transformer

Inherits:
Object
  • Object
show all
Defined in:
lib/imgproxy-rails/transformer.rb

Constant Summary collapse

MAP =
{
  resize: proc do |p|
    width, height = p.split("x")
    {width: width, height: height}
  end,
  resize_to_limit: proc { |p| {width: p[0], height: p[1]} },
  resize_to_fit: proc { |p| {width: p[0], height: p[1], enlarge: true} },
  resize_to_fill: proc { |p| {width: p[0], height: p[1], resizing_type: :fill, enlarge: true} },
  resize_and_pad: proc { |p| resize_and_pad(p) },
  convert: proc { |p| {format: p} },
  trim: proc { {trim: 0} },
  modulate: proc { |p| modulate(p) }
}.freeze
GRAVITY =
{
  "north" => "no",
  "north-east" => "noea",
  "east" => "ea",
  "south-east" => "soea",
  "south" => "so",
  "south-west" => "sowe",
  "west" => "we",
  "north-west" => "nowe",
  "centre" => "ce"
}.freeze
PASSTHROUGH_OPTIONS =
Set.new([
  "rotate",
  "sharpen",
  "blur",
  "quality"
]).freeze

Class Method Summary collapse

Class Method Details

.call(transformations) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/imgproxy-rails/transformer.rb', line 39

def call(transformations)
  passed_options = transformations.delete(:imgproxy_options) || {}
  mapped_options = transformations.each_with_object({}) do |(t_key, t_value), memo|
    if PASSTHROUGH_OPTIONS.include?(t_key.to_s)
      memo[t_key] = t_value
      next
    end
    memo.merge!(MAP[t_key].call(t_value)) if MAP.key?(t_key)
  end
  mapped_options.merge(passed_options)
end