imgproxy 1.0.6 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95f295a470a117f44dff275879b3c048d4c0553ccb121f448b34c9282c1bebcc
4
- data.tar.gz: 90aef03fecd81f74a7e3d73fe465ef7ff4e35e8cf9fdee605aa50edefe03da9c
3
+ metadata.gz: 408a45b49e0ddd25815dd6a3f904a93a9df27e9d00e31dcfccab11a9cf841196
4
+ data.tar.gz: b43ff3e7f9c80922937729921ea1a2fc5187974298ff19f5190191ff2a2d4b95
5
5
  SHA512:
6
- metadata.gz: a04dfc605cc6143e67555de585f91dbcb443f09043e55eb66dad31f20a156cb8b1a6654f44c7c9f3e5458bd3ea089287bfe361747ee27426132b3512223de648
7
- data.tar.gz: 5138489ca03ddb7f1835ae670a0dda2bf4d9c234f19a524f5189e7a61b203b81401c474886f5c659d1dbc57f0e797479f538c81d3be0d51ee4a78a1fca37d336
6
+ metadata.gz: d92e1e4782e614a0f445766e4f1d4b6b985564e4877b1a0230b2717b337acfea7d2ff09ff12cc9cbf1ea86312a5bc7c2c382102a9651f3e390ea4cdb7fadc68b
7
+ data.tar.gz: 6de6077c86b0d9a83dcb3673d35b9a28a0586ec9612211d233ed8fffc935de5ee8c587311fe695c7df882a3af42b558e221ac5f081a308274ace6c102a5ddf69
data/README.md CHANGED
@@ -171,10 +171,15 @@ builder.url_for("http://images.example.com/images/image2.jpg")
171
171
  * `gravity_x`, `gravity_y` — floating point numbers between 0 and 1 that define the coordinates of the center of the resulting image when `fp` gravity is used.
172
172
  * `quality` — defines the quality of the resulting image, percentage.
173
173
  * `background` — when set, imgproxy will fill the resulting image background with the specified color. Can be a hex-color string or an array of red, green and blue values (0-255).
174
+ * `brightness` — when set, imgproxy will adjust brightness of the resulting image. _Supported only by imgproxy pro._
175
+ * `contrast` — when set, imgproxy will adjust contrast of the resulting image. _Supported only by imgproxy pro._
176
+ * `saturation` — when set, imgproxy will adjust saturation of the resulting image. _Supported only by imgproxy pro._
174
177
  * `blur` — when set, imgproxy will apply the gaussian blur filter to the resulting image. Value is the size of a mask imgproxy will use.
175
178
  * `sharpen` — when set, imgproxy will apply the sharpen filter to the resulting image. Value is the size of a mask imgproxy will use.
179
+ * `pixelate` — when set, imgproxy will apply the pixelate filter to the resulting image. Value is the size of a pixel. _Supported only by imgproxy pro._
176
180
  * `watermark_opacity` — when set, imgproxy will put a watermark on the resulting image. See [watermars guide](https://github.comimgproxym/imgproxy/blob/master/docs/watermark.md) for more info.
177
181
  * `watermark_position`, `watermark_x_offset`, `watermark_y_offset`, `watermark_scale` — additional watermark options described in the [watermars guide](https://github.com/imgproxy/imgproxy/blob/master/docs/watermark.md).
182
+ * `style` - when set, imgproxy will prepend `<style>` node with provided content to the `<svg>` node of source SVG image. _Supported only by imgproxy pro._
178
183
  * `preset` — array of names of presets that will be used by imgproxy. See [presets guide](https://github.com/imgproxy/imgproxy/blob/master/docs/presets.md) for more info.
179
184
  * `cachebuster` — defines cache buster that doesn't affect image processing but it's changing allows to bypass CDN, proxy server and browser cache.
180
185
  * `format` — specifies the resulting image format (`jpg`, `png`, `webp`).
@@ -45,6 +45,11 @@ module Imgproxy
45
45
  # @param [String,URI, Object] image Source image URL or object applicable for
46
46
  # the configured URL adapters
47
47
  # @param [Hash] options Processing options
48
+ # @option options [Integer] :crop_width
49
+ # @option options [Integer] :crop_height
50
+ # @option options [String] :crop_gravity
51
+ # @option options [Float] :crop_gravity_x
52
+ # @option options [Float] :crop_gravity_y
48
53
  # @option options [String] :resizing_type
49
54
  # @option options [Integer] :width
50
55
  # @option options [Integer] :height
@@ -56,13 +61,18 @@ module Imgproxy
56
61
  # @option options [Float] :gravity_y
57
62
  # @option options [Integer] :quality
58
63
  # @option options [Array] :background
64
+ # @option options [Integer] :brightness supported only by imgproxy pro
65
+ # @option options [Float] :contrast supported only by imgproxy pro
66
+ # @option options [Float] :saturation supported only by imgproxy pro
59
67
  # @option options [Float] :blur
60
68
  # @option options [Float] :sharpen
69
+ # @option options [Integer] :pixelate supported only by imgproxy pro
61
70
  # @option options [Float] :watermark_opacity
62
71
  # @option options [String] :watermark_position
63
72
  # @option options [Integer] :watermark_x_offset
64
73
  # @option options [Integer] :watermark_y_offset
65
74
  # @option options [Float] :watermark_scale
75
+ # @option options [String] :style supported only by imgproxy pro
66
76
  # @option options [Array] :preset
67
77
  # @option options [String] :cachebuster
68
78
  # @option options [String] :format
@@ -46,6 +46,7 @@ module Imgproxy
46
46
  private
47
47
 
48
48
  OPTIONS_ALIASES = {
49
+ crop: :c,
49
50
  resize: :rs,
50
51
  size: :s,
51
52
  resizing_type: :rt,
@@ -56,9 +57,15 @@ module Imgproxy
56
57
  gravity: :g,
57
58
  quality: :q,
58
59
  background: :bg,
60
+ adjust: :a,
61
+ brightness: :br,
62
+ contrast: :co,
63
+ saturation: :sa,
59
64
  blur: :bl,
60
65
  sharpen: :sh,
66
+ pixelate: :pix,
61
67
  watermark: :wm,
68
+ watermark_url: :wmu,
62
69
  preset: :pr,
63
70
  cachebuster: :cb,
64
71
  }.freeze
@@ -1,15 +1,19 @@
1
1
  module Imgproxy
2
2
  # Formats and regroups processing options
3
3
  class Options < Hash
4
- STRING_OPTS = %i[resizing_type gravity watermark_position style cachebuster format].freeze
5
- INT_OPTS = %i[width height quality watermark_x_offset watermark_y_offset].freeze
6
- FLOAT_OPTS = %i[dpr gravity_x gravity_y blur sharpen watermark_opacity watermark_scale].freeze
4
+ STRING_OPTS = %i[resizing_type gravity crop_gravity watermark_position watermark_url style
5
+ cachebuster format].freeze
6
+ INT_OPTS = %i[width height crop_width crop_height
7
+ quality brightness pixelate watermark_x_offset watermark_y_offset].freeze
8
+ FLOAT_OPTS = %i[dpr gravity_x gravity_y crop_gravity_x crop_gravity_y contrast saturation
9
+ blur sharpen watermark_opacity watermark_scale].freeze
7
10
  BOOL_OPTS = %i[enlarge extend].freeze
8
11
  ARRAY_OPTS = %i[background preset].freeze
9
12
  ALL_OPTS = (STRING_OPTS + INT_OPTS + FLOAT_OPTS + BOOL_OPTS + ARRAY_OPTS).freeze
10
13
 
11
- OPTS_PRIORITY = %i[ resize size resizing_type width height dpr enlarge extend gravity quality
12
- background blur sharpen watermark preset cachebuster ].freeze
14
+ OPTS_PRIORITY = %i[ crop resize size resizing_type width height dpr enlarge extend gravity
15
+ quality background blur sharpen pixelate watermark watermark_url preset
16
+ cachebuster ].freeze
13
17
 
14
18
  # @param options [Hash] raw processing options
15
19
  def initialize(options)
@@ -17,11 +21,10 @@ module Imgproxy
17
21
 
18
22
  typecast
19
23
 
20
- group_resizing_opts
21
- group_gravity_opts
22
- group_watermark_opts
24
+ group_options
23
25
 
24
26
  encode_style
27
+ encode_watermark_url
25
28
 
26
29
  replace(Hash[sort_by { |k, _| OPTS_PRIORITY.index(k) || 99 }])
27
30
 
@@ -51,37 +54,53 @@ module Imgproxy
51
54
  value.is_a?(Array) ? value : [value]
52
55
  end
53
56
 
57
+ def group_options
58
+ group_crop_opts
59
+ group_resizing_opts
60
+ group_gravity_opts
61
+ group_adjust_opts
62
+ group_watermark_opts
63
+ end
64
+
65
+ def group_crop_opts
66
+ crop_width = delete(:crop_width)
67
+ crop_height = delete(:crop_height)
68
+ crop_gravity = extract_and_trim_nils(:crop_gravity, :crop_gravity_x, :crop_gravity_y)
69
+
70
+ return unless crop_width || crop_height
71
+
72
+ crop_gravity = nil if crop_gravity[0].nil?
73
+
74
+ self[:crop] = [crop_width || 0, crop_height || 0, *crop_gravity]
75
+ end
76
+
54
77
  def group_resizing_opts
55
78
  return unless self[:width] && self[:height]
56
79
 
57
- self[:size] = trim_nils(
58
- [delete(:width), delete(:height), delete(:enlarge), delete(:extend)],
59
- )
80
+ self[:size] = extract_and_trim_nils(:width, :height, :enlarge, :extend)
60
81
 
61
82
  self[:resize] = [delete(:resizing_type), *delete(:size)] if self[:resizing_type]
62
83
  end
63
84
 
64
85
  def group_gravity_opts
65
- gravity = trim_nils(
66
- [
67
- delete(:gravity),
68
- delete(:gravity_x),
69
- delete(:gravity_y),
70
- ],
71
- )
86
+ gravity = extract_and_trim_nils(:gravity, :gravity_x, :gravity_y)
72
87
 
73
88
  self[:gravity] = gravity unless gravity[0].nil?
74
89
  end
75
90
 
91
+ def group_adjust_opts
92
+ return unless values_at(:brightness, :contrast, :saturation).count { |o| !o.nil? } > 1
93
+
94
+ self[:adjust] = extract_and_trim_nils(:brightness, :contrast, :saturation)
95
+ end
96
+
76
97
  def group_watermark_opts
77
- watermark = trim_nils(
78
- [
79
- delete(:watermark_opacity),
80
- delete(:watermark_position),
81
- delete(:watermark_x_offset),
82
- delete(:watermark_y_offset),
83
- delete(:watermark_scale),
84
- ],
98
+ watermark = extract_and_trim_nils(
99
+ :watermark_opacity,
100
+ :watermark_position,
101
+ :watermark_x_offset,
102
+ :watermark_y_offset,
103
+ :watermark_scale,
85
104
  )
86
105
 
87
106
  self[:watermark] = watermark unless watermark[0].nil?
@@ -92,6 +111,15 @@ module Imgproxy
92
111
  self[:style] = Base64.urlsafe_encode64(self[:style]).tr("=", "")
93
112
  end
94
113
 
114
+ def encode_watermark_url
115
+ return if self[:watermark_url].nil?
116
+ self[:watermark_url] = Base64.urlsafe_encode64(self[:watermark_url]).tr("=", "")
117
+ end
118
+
119
+ def extract_and_trim_nils(*keys)
120
+ trim_nils(keys.map { |k| delete(k) })
121
+ end
122
+
95
123
  def trim_nils(value)
96
124
  value.delete_at(-1) while !value.empty? && value[-1].nil?
97
125
  value
@@ -1,3 +1,3 @@
1
1
  module Imgproxy
2
- VERSION = "1.0.6".freeze
2
+ VERSION = "1.1.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imgproxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Alexandrovich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-24 00:00:00.000000000 Z
11
+ date: 2019-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry-byebug