Class: Imgproxy::Options

Inherits:
Hash
  • Object
show all
Defined in:
lib/imgproxy/options.rb

Overview

Formats and regroups processing options

Constant Summary collapse

STRING_OPTS =
i[resizing_type gravity crop_gravity watermark_position watermark_url style
cachebuster format].freeze
INT_OPTS =
i[width height crop_width crop_height
quality brightness pixelate watermark_x_offset watermark_y_offset].freeze
FLOAT_OPTS =
i[dpr gravity_x gravity_y crop_gravity_x crop_gravity_y contrast saturation
blur sharpen watermark_opacity watermark_scale].freeze
BOOL_OPTS =
i[enlarge extend].freeze
ARRAY_OPTS =
i[background preset].freeze
ALL_OPTS =
(STRING_OPTS + INT_OPTS + FLOAT_OPTS + BOOL_OPTS + ARRAY_OPTS).freeze
OPTS_PRIORITY =
i[ crop resize size resizing_type width height dpr enlarge extend gravity
quality background blur sharpen pixelate watermark watermark_url preset
cachebuster ].freeze

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Options

Returns a new instance of Options.

Parameters:

  • options (Hash)

    raw processing options



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/imgproxy/options.rb', line 19

def initialize(options)
  merge!(options.slice(*ALL_OPTS))

  typecast

  group_options

  encode_style
  encode_watermark_url

  replace(Hash[sort_by { |k, _| OPTS_PRIORITY.index(k) || 99 }])

  freeze
end