imgproxy 1.1.0 → 1.2.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: 408a45b49e0ddd25815dd6a3f904a93a9df27e9d00e31dcfccab11a9cf841196
4
- data.tar.gz: b43ff3e7f9c80922937729921ea1a2fc5187974298ff19f5190191ff2a2d4b95
3
+ metadata.gz: 138bb555a390e397e8bdc3e5f68534416bac212660f1c48aa2fc8332e5ab4828
4
+ data.tar.gz: 73d3c3357b1eb2959084b827e790e2aaa2145499ec69539a069d47e02e160c43
5
5
  SHA512:
6
- metadata.gz: d92e1e4782e614a0f445766e4f1d4b6b985564e4877b1a0230b2717b337acfea7d2ff09ff12cc9cbf1ea86312a5bc7c2c382102a9651f3e390ea4cdb7fadc68b
7
- data.tar.gz: 6de6077c86b0d9a83dcb3673d35b9a28a0586ec9612211d233ed8fffc935de5ee8c587311fe695c7df882a3af42b558e221ac5f081a308274ace6c102a5ddf69
6
+ metadata.gz: 8891f46189c8b7a646d8fbed5202e7b66f51e63357b999158fc71c3fae19b5d3ae38a48c21f2acac7d937b6f53c512fe4f4654c528bb1a3e4a83ade50f065535
7
+ data.tar.gz: 82821cd8bd891a5dc0ed51846e490b09228ac070e2d0b1dd8af544c8046fc998f628e2cd283ee8011e7d365b2a3c087241129b3fe0d8c88d13e751b260fa9b5b
data/README.md CHANGED
@@ -51,6 +51,9 @@ Imgproxy.configure do |config|
51
51
  config.hex_key = "your_key"
52
52
  # Hex-encoded signature salt
53
53
  config.hex_salt = "your_salt"
54
+
55
+ # Base64 encode all URLs
56
+ # config.base64_encode_urls = true
54
57
  end
55
58
  ```
56
59
 
@@ -167,9 +170,16 @@ builder.url_for("http://images.example.com/images/image2.jpg")
167
170
  * `dpr` — when set, imgproxy will multiply the image dimensions according to this factor for HiDPI (Retina) devices.
168
171
  * `enlarge` — when true, imgproxy will enlarge the image if it is smaller than the given size.
169
172
  * `extend` — when true, imgproxy will extend the image if the resizing result is smaller than the given size.
173
+ * `extend_gravity`, `extend_gravity_x`, `extend_gravity_y` — define the gravity of the extend. These options accept the same values as `gravity`, `gravity_x` and `gravity_y` (see below).
170
174
  * `gravity` — defines gravity that will be used when imgproxy needs to cut some parts of the image. See [URL format guide](https://github.com/imgproxy/imgproxy/blob/master/docs/generating_the_url_advanced.md#gravity) for available values.
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.
175
+ * `gravity_x`, `gravity_y` — specify gravity offset by X and Y axes. When `fp` gravity is used, these are floating point numbers between 0 and 1 that define the coordinates of the center of the resulting image.
176
+ * `crop_width`, `crop_height` — define the size of an area of the image to be processed (crop before resize).
177
+ * `crop_gravity`, `crop_gravity_x`, `crop_gravity_y` - define the gravity of the crop. These options accept the same values as `gravity`, `gravity_x` and `gravity_y` (see above).
178
+ * `padding` - defines padding size in css manner (you can use array here). See [URL guide](https://docs.imgproxy.net/#/generating_the_url_advanced?id=padding) for more info.
179
+ * `trim_threshold` - when set, imgproxy removes surrounding background.
180
+ * `trim_color`, `trim_equal_hor`, `trim_equal_ver` - additional trim options described in the [URL guide](https://docs.imgproxy.net/#/generating_the_url_advanced?id=trim).
172
181
  * `quality` — defines the quality of the resulting image, percentage.
182
+ * `max_bytes` — when set, imgproxy automatically degrades the quality of the image until the image is under the specified amount of bytes.
173
183
  * `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
184
  * `brightness` — when set, imgproxy will adjust brightness of the resulting image. _Supported only by imgproxy pro._
175
185
  * `contrast` — when set, imgproxy will adjust contrast of the resulting image. _Supported only by imgproxy pro._
@@ -179,10 +189,12 @@ builder.url_for("http://images.example.com/images/image2.jpg")
179
189
  * `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._
180
190
  * `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.
181
191
  * `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._
192
+ * `watermark_url` when set, imgproxy will use the image from the specified URL as a watermark. _Supported only by imgproxy pro._
193
+ * `style` — when set, imgproxy will prepend `<style>` node with provided content to the `<svg>` node of source SVG image. _Supported only by imgproxy pro._
183
194
  * `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.
184
195
  * `cachebuster` — defines cache buster that doesn't affect image processing but it's changing allows to bypass CDN, proxy server and browser cache.
185
196
  * `format` — specifies the resulting image format (`jpg`, `png`, `webp`).
197
+ * `base64_encode_url` — encode the URL as a base64 string.
186
198
  * `use_short_options` — per-call redefinition of `use_short_options` config.
187
199
 
188
200
  **See [imgproxy URL format guide](https://github.com/imgproxy/imgproxy/blob/master/docs/generating_the_url_advanced.md) for more info.**
@@ -253,3 +265,7 @@ If you are having any problems with image processing of imgproxy itself, be sure
253
265
  ## License
254
266
 
255
267
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
268
+
269
+ ## Security Contact
270
+
271
+ To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
@@ -45,21 +45,30 @@ 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
53
48
  # @option options [String] :resizing_type
54
49
  # @option options [Integer] :width
55
50
  # @option options [Integer] :height
56
51
  # @option options [Float] :dpr
57
52
  # @option options [Boolean] :enlarge
58
53
  # @option options [Boolean] :extend
54
+ # @option options [String] :extend_gravity
55
+ # @option options [Float] :extend_gravity_x
56
+ # @option options [Float] :extend_gravity_y
59
57
  # @option options [String] :gravity
60
58
  # @option options [Float] :gravity_x
61
59
  # @option options [Float] :gravity_y
60
+ # @option options [Integer] :crop_width
61
+ # @option options [Integer] :crop_height
62
+ # @option options [String] :crop_gravity
63
+ # @option options [Float] :crop_gravity_x
64
+ # @option options [Float] :crop_gravity_y
65
+ # @option options [Integer] :trim_threshold
66
+ # @option options [String] :trim_color
67
+ # @option options [Array] :padding
68
+ # @option options [Boolean] :trim_equal_hor
69
+ # @option options [Boolean] :trim_equal_ver
62
70
  # @option options [Integer] :quality
71
+ # @option options [Integer] :max_bytes
63
72
  # @option options [Array] :background
64
73
  # @option options [Integer] :brightness supported only by imgproxy pro
65
74
  # @option options [Float] :contrast supported only by imgproxy pro
@@ -77,6 +86,7 @@ module Imgproxy
77
86
  # @option options [String] :cachebuster
78
87
  # @option options [String] :format
79
88
  # @option options [Boolean] :use_short_options
89
+ # @option options [Boolean] :base64_encode_urls
80
90
  # @see https://github.com/DarthSim/imgproxy/blob/master/docs/generating_the_url_advanced.md
81
91
  # imgproxy URL format documentation
82
92
  def url_for(image, options = {})
@@ -17,13 +17,17 @@ module Imgproxy
17
17
  # builder.url_for("http://images.example.com/images/image1.jpg")
18
18
  # builder.url_for("http://images.example.com/images/image2.jpg")
19
19
  class Builder
20
+ OMITTED_OPTIONS = %i[format].freeze
20
21
  # @param [Hash] options Processing options
21
22
  # @see Imgproxy.url_for
22
23
  def initialize(options = {})
23
24
  options = options.dup
24
25
 
26
+ @base64_encode_url = options.delete(:base64_encode_url)
25
27
  @use_short_options = options.delete(:use_short_options)
28
+
26
29
  @use_short_options = config.use_short_options if @use_short_options.nil?
30
+ @base64_encode_url = config.base64_encode_urls if @base64_encode_url.nil?
27
31
 
28
32
  @options = Imgproxy::Options.new(options)
29
33
  end
@@ -35,9 +39,7 @@ module Imgproxy
35
39
  # the configured URL adapters
36
40
  # @see Imgproxy.url_for
37
41
  def url_for(image)
38
- path = [*processing_options, "plain", url(image)].join("/")
39
- path = "#{path}@#{@options[:format]}" if @options[:format]
40
-
42
+ path = [*processing_options, url(image)].join("/")
41
43
  signature = sign_path(path)
42
44
 
43
45
  File.join(Imgproxy.config.endpoint.to_s, signature, path)
@@ -46,7 +48,6 @@ module Imgproxy
46
48
  private
47
49
 
48
50
  OPTIONS_ALIASES = {
49
- crop: :c,
50
51
  resize: :rs,
51
52
  size: :s,
52
53
  resizing_type: :rt,
@@ -55,7 +56,11 @@ module Imgproxy
55
56
  enlarge: :en,
56
57
  extend: :ex,
57
58
  gravity: :g,
59
+ crop: :c,
60
+ padding: :pd,
61
+ trim: :t,
58
62
  quality: :q,
63
+ max_bytes: :mb,
59
64
  background: :bg,
60
65
  adjust: :a,
61
66
  brightness: :br,
@@ -74,11 +79,23 @@ module Imgproxy
74
79
 
75
80
  def processing_options
76
81
  @processing_options ||=
77
- @options.reject { |k, _| k == :format }.map do |key, value|
82
+ @options.reject { |k, _| OMITTED_OPTIONS.include?(k) }.map do |key, value|
78
83
  "#{option_alias(key)}:#{wrap_array(value).join(':')}"
79
84
  end
80
85
  end
81
86
 
87
+ def plain_url_for(url)
88
+ escaped_url = url.match?(NEED_ESCAPE_RE) ? ERB::Util.url_encode(url) : url
89
+
90
+ @options[:format] ? "plain/#{escaped_url}@#{@options[:format]}" : "plain/#{escaped_url}"
91
+ end
92
+
93
+ def base64_url_for(url)
94
+ encoded_url = Base64.urlsafe_encode64(url).tr("=", "").scan(/.{1,16}/).join("/")
95
+
96
+ @options[:format] ? "#{encoded_url}.#{@options[:format]}" : encoded_url
97
+ end
98
+
82
99
  def option_alias(name)
83
100
  return name unless config.use_short_options
84
101
 
@@ -91,7 +108,8 @@ module Imgproxy
91
108
 
92
109
  def url(image)
93
110
  url = config.url_adapters.url_of(image)
94
- url.match?(NEED_ESCAPE_RE) ? ERB::Util.url_encode(url) : url
111
+
112
+ @base64_encode_url ? base64_url_for(url) : plain_url_for(url)
95
113
  end
96
114
 
97
115
  def sign_path(path)
@@ -17,9 +17,14 @@ module Imgproxy
17
17
  # Defaults to true
18
18
  attr_accessor :use_short_options
19
19
 
20
+ # @return [Boolean] base64 encode the URL
21
+ # Defaults to false
22
+ attr_accessor :base64_encode_urls
23
+
20
24
  def initialize
21
25
  self.signature_size = 32
22
26
  self.use_short_options = true
27
+ self.base64_encode_urls = false
23
28
  end
24
29
 
25
30
  # Decodes hex-encoded key and sets it to {#key}
@@ -1,18 +1,20 @@
1
1
  module Imgproxy
2
2
  # Formats and regroups processing options
3
3
  class Options < Hash
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
10
- BOOL_OPTS = %i[enlarge extend].freeze
11
- ARRAY_OPTS = %i[background preset].freeze
4
+ STRING_OPTS = %i[resizing_type extend_gravity gravity crop_gravity trim_color watermark_position
5
+ watermark_url style cachebuster format base64_encode_url].freeze
6
+ INT_OPTS = %i[width height crop_width crop_height trim_threshold quality brightness pixelate
7
+ watermark_x_offset watermark_y_offset max_bytes].freeze
8
+ FLOAT_OPTS = %i[dpr extend_gravity_x extend_gravity_y gravity_x gravity_y crop_gravity_x
9
+ crop_gravity_y contrast saturation blur sharpen watermark_opacity
10
+ watermark_scale].freeze
11
+ BOOL_OPTS = %i[enlarge extend trim_equal_hor trim_equal_ver].freeze
12
+ ARRAY_OPTS = %i[padding background preset].freeze
12
13
  ALL_OPTS = (STRING_OPTS + INT_OPTS + FLOAT_OPTS + BOOL_OPTS + ARRAY_OPTS).freeze
13
14
 
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
15
+ OPTS_PRIORITY = %i[ resize size resizing_type width height dpr enlarge extend gravity
16
+ crop padding trim quality max_bytes background adjust brightness contrast
17
+ saturation blur sharpen pixelate watermark watermark_url style preset
16
18
  cachebuster ].freeze
17
19
 
18
20
  # @param options [Hash] raw processing options
@@ -56,10 +58,12 @@ module Imgproxy
56
58
 
57
59
  def group_options
58
60
  group_crop_opts
61
+ group_extend_opts
59
62
  group_resizing_opts
60
63
  group_gravity_opts
61
64
  group_adjust_opts
62
65
  group_watermark_opts
66
+ group_trim_opts
63
67
  end
64
68
 
65
69
  def group_crop_opts
@@ -88,6 +92,16 @@ module Imgproxy
88
92
  self[:gravity] = gravity unless gravity[0].nil?
89
93
  end
90
94
 
95
+ def group_extend_opts
96
+ extend_opts =
97
+ extract_and_trim_nils(:extend, :extend_gravity, :extend_gravity_x, :extend_gravity_y)
98
+
99
+ return if extend_opts[0].nil?
100
+ return self[:extend] = 0 if extend_opts[0].zero?
101
+
102
+ self[:extend] = extend_opts
103
+ end
104
+
91
105
  def group_adjust_opts
92
106
  return unless values_at(:brightness, :contrast, :saturation).count { |o| !o.nil? } > 1
93
107
 
@@ -106,6 +120,17 @@ module Imgproxy
106
120
  self[:watermark] = watermark unless watermark[0].nil?
107
121
  end
108
122
 
123
+ def group_trim_opts
124
+ trim = extract_and_trim_nils(
125
+ :trim_threshold,
126
+ :trim_color,
127
+ :trim_equal_hor,
128
+ :trim_equal_ver,
129
+ )
130
+
131
+ self[:trim] = trim unless trim[0].nil?
132
+ end
133
+
109
134
  def encode_style
110
135
  return if self[:style].nil?
111
136
  self[:style] = Base64.urlsafe_encode64(self[:style]).tr("=", "")
@@ -13,7 +13,8 @@ module Imgproxy
13
13
  end
14
14
 
15
15
  def url(image)
16
- "s3://#{image.storage.bucket.name}/#{image.id}"
16
+ path = [*image.storage.prefix, image.id].join("/")
17
+ "s3://#{image.storage.bucket.name}/#{path}"
17
18
  end
18
19
  end
19
20
  end
@@ -1,3 +1,3 @@
1
1
  module Imgproxy
2
- VERSION = "1.1.0".freeze
2
+ VERSION = "1.2.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.1.0
4
+ version: 1.2.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-10-14 00:00:00.000000000 Z
11
+ date: 2020-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry-byebug
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.6.0
19
+ version: 3.9.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 3.6.0
26
+ version: 3.9.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 3.8.0
33
+ version: 3.9.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 3.8.0
40
+ version: 3.9.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec_junit_formatter
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,42 +58,42 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.66.0
61
+ version: 0.83.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.66.0
68
+ version: 0.83.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop-rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.32.0
75
+ version: 1.38.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.32.0
82
+ version: 1.38.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: aws-sdk-s3
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 1.35.0
89
+ version: 1.64.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 1.35.0
96
+ version: 1.64.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: google-cloud-storage
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -128,28 +128,28 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '2.16'
131
+ version: '3.0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '2.16'
138
+ version: '3.0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: sqlite3
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 1.3.6
145
+ version: 1.4.1
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 1.3.6
152
+ version: 1.4.1
153
153
  description: A gem that easily generates imgproxy URLs for your images
154
154
  email: darthsim@gmail.com
155
155
  executables: []
@@ -190,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
190
  - !ruby/object:Gem::Version
191
191
  version: '0'
192
192
  requirements: []
193
- rubygems_version: 3.0.2
193
+ rubygems_version: 3.0.3
194
194
  signing_key:
195
195
  specification_version: 4
196
196
  summary: imgproxy URL generator