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 extend_gravity gravity crop_gravity trim_color watermark_position
watermark_url style cachebuster format base64_encode_url].freeze
INT_OPTS =
i[width height crop_width crop_height trim_threshold quality brightness pixelate
watermark_x_offset watermark_y_offset max_bytes].freeze
FLOAT_OPTS =
i[dpr extend_gravity_x extend_gravity_y gravity_x gravity_y crop_gravity_x
crop_gravity_y contrast saturation blur sharpen watermark_opacity
watermark_scale].freeze
BOOL_OPTS =
i[enlarge extend trim_equal_hor trim_equal_ver].freeze
ARRAY_OPTS =
i[padding background preset].freeze
ALL_OPTS =
(STRING_OPTS + INT_OPTS + FLOAT_OPTS + BOOL_OPTS + ARRAY_OPTS).freeze
OPTS_PRIORITY =
i[ resize size resizing_type width height dpr enlarge extend gravity
crop padding trim quality max_bytes background adjust brightness contrast
saturation blur sharpen pixelate watermark watermark_url style preset
cachebuster ].freeze

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Options

Returns a new instance of Options.

Parameters:

  • options (Hash)

    raw processing options



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

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