image_processing 2.2.1 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f36b1a00b35a05403a2c6dd77f94912dbbca311cb6939556cbb7e9eb66cd702
4
- data.tar.gz: bce160c3fcff5a046447c334c4c5440386080d355b0899c30b5b1ea6e89922c8
3
+ metadata.gz: 5a81c5c941680dad68dc945c6943645401e6d1c7c18dc5bfaf17ca0c815204af
4
+ data.tar.gz: 725c0f80e462375fe2b7e46800947a9fc9410890d49b5e12f50a6e781c458ce9
5
5
  SHA512:
6
- metadata.gz: 61b02322af114f81116e9f3600d5f331cacb8b6c299a78a15c9891d56beb92ee56f4181b3349b64087bd3d801aa90029ee31e5e897847ea4bb9739589bcc3305
7
- data.tar.gz: ba62cf185ca3ac4a19582936c3fbca176b7e8312185fd3505438b247e839a877ac53781cf518311b6a5ff3601111529393a00649b0e395b5b42bbeec3de27f8d
6
+ metadata.gz: 8853de6a2dd8e43a0b50abd1cd47f82d67142ee6b6d915944b24ce249a0a07e576c12624913c5d4de57fba657d15c3717ce95ad1b00d2203717aaae28bfa161b
7
+ data.tar.gz: dec521c4414f9c31a450e86976c3405f380d0a91704a618159fb6ba133ee1baca5f1d89b7b5158008e9e16d823b28469359d9a0f3a1c76af9417f0533cb1cb46
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.2.2 (2026-11-22)
2
+
3
+ * Allow operations defined in modules mixed into a processor or accumulator class again (e.g. `ImageProcessing::Vips::Processor.include(MyMacros)`), which 2.2.1 rejected
4
+
1
5
  ## 2.2.1 (2026-11-21)
2
6
 
3
7
  * Prevent remote code execution when operation names or MiniMagick loader/saver option names come from user input and a library such as ActiveSupport adds methods like `Object#try` to every object (reported by @hgrgr)
@@ -24,7 +28,7 @@
24
28
 
25
29
  ## 2.0.1 (2026-05-22)
26
30
 
27
- * [minimagick] Prevent remote shell execution when passing loader/saver options from user input
31
+ * [minimagick] Prevent remote shell execution when passing loader/saver options from user input (reported by @bilerden)
28
32
 
29
33
  ## 2.0.0 (2026-05-20)
30
34
 
data/README.md CHANGED
@@ -28,28 +28,27 @@ how to resize and process images.
28
28
 
29
29
  1. Install ImageMagick and/or libvips:
30
30
 
31
- In a Mac terminal:
31
+ On macOS:
32
32
 
33
- ```sh
34
- $ brew install imagemagick # if using ImageMagick
35
- $ brew install vips # if using libvips
36
- ```
33
+ ```sh
34
+ $ brew install imagemagick # if using ImageMagick
35
+ $ brew install vips # if using libvips
36
+ ```
37
37
 
38
- In a debian/ubuntu terminal:
38
+ On Debian/Ubuntu:
39
39
 
40
- ```sh
41
- $ sudo apt install imagemagick # if using ImageMagick
42
- $ sudo apt install libvips # if using libvips
43
- ```
40
+ ```sh
41
+ $ sudo apt install imagemagick # if using ImageMagick
42
+ $ sudo apt install libvips # if using libvips
43
+ ```
44
44
 
45
45
  2. Add the gem(s) to your Gemfile:
46
46
 
47
- ```rb
48
- gem "image_processing", "~> 2.0"
49
- gem "mini_magick", "~> 5.0" # if using ImageMagick
50
- gem "ruby-vips", "~> 2.0" # if using libvips
51
- ```
52
-
47
+ ```rb
48
+ gem "image_processing", "~> 2.0"
49
+ gem "mini_magick", "~> 5.0" # if using ImageMagick
50
+ gem "ruby-vips", "~> 2.0" # if using libvips
51
+ ```
53
52
 
54
53
  ## Usage
55
54
 
@@ -124,12 +123,13 @@ pipeline.options
124
123
  # :saver=>{},
125
124
  # :format=>"png",
126
125
  # :operations=>[[:resize_to_limit, [400, 400]], [:strip, []]],
127
- # :processor_class=>ImageProcessing::MiniMagick::Processor}
126
+ # :processor=>ImageProcessing::MiniMagick::Processor}
128
127
  ```
129
128
 
130
- The source object needs to responds to `#path`, or be a String, a Pathname, or
131
- a `Vips::Image`/`MiniMagick::Tool` object. Note that the processed file is
132
- always saved to a new location, in-place processing is not supported.
129
+ The source object needs to respond to `#path`, or be a String, a Pathname, or
130
+ a `Vips::Image`/`MiniMagick::Tool` object. If no source is given,
131
+ `ImageProcessing::Error` is raised. Note that the processed file is always saved
132
+ to a new location, in-place processing is not supported.
133
133
 
134
134
  ```rb
135
135
  ImageProcessing::Vips.source(File.open("source.jpg"))
@@ -148,9 +148,18 @@ pipeline = ImageProcessing::Vips.source(image)
148
148
 
149
149
  pipeline.call #=> #<Tempfile ...>
150
150
  pipeline.call(save: false) #=> #<Vips::Image ...>
151
- pipeline.call(destination: "/path/to/destination")
151
+ pipeline.call(destination: "/path/to/destination.jpg")
152
152
  ```
153
153
 
154
+ When saving to a tempfile, the output format is the one passed to `#convert`,
155
+ falling back to the extension of the source file, and finally to JPEG. When
156
+ saving to a `:destination` path, the format is determined by the path's
157
+ extension; if the path has no extension (e.g. `/dev/fd/N`), the format passed
158
+ to `#convert` is used.
159
+
160
+ If processing fails while saving to a `:destination` path that didn't exist
161
+ before, the partially written file is deleted before the error is re-raised.
162
+
154
163
  You can continue reading the API documentation for specific modules:
155
164
 
156
165
  * **[`ImageProcessing::Vips`]**
@@ -159,10 +168,44 @@ You can continue reading the API documentation for specific modules:
159
168
  See the **[wiki]** for additional "How To" guides for common scenarios. The wiki
160
169
  is publicly editable, so you're encouraged to add your own guides.
161
170
 
171
+ ## Applying operations from a hash
172
+
173
+ Instead of chaining methods, you can pass operations as a hash to `#apply`,
174
+ which is handy when the processing steps are stored as data (e.g. Active
175
+ Storage variants). Hash keys are the builder methods to call, and values are
176
+ the arguments: a single argument, an array of arguments, a hash of keyword
177
+ arguments, or `true`/`nil` for no arguments.
178
+
179
+ ```rb
180
+ ImageProcessing::Vips
181
+ .source(image)
182
+ .apply(resize_to_limit: [400, 400], sharpen: true, convert: "png")
183
+ .call
184
+
185
+ # equivalent to
186
+
187
+ ImageProcessing::Vips
188
+ .source(image)
189
+ .resize_to_limit(400, 400)
190
+ .sharpen
191
+ .convert("png")
192
+ .call
193
+ ```
194
+
195
+ To call the same method more than once, pass an array of pairs instead:
196
+
197
+ ```rb
198
+ ImageProcessing::Vips
199
+ .apply([[:rotate, 90], [:rotate, 90]])
200
+ ```
201
+
162
202
  ## Instrumentation
163
203
 
164
204
  You can register an `#instrumenter` block for a given pipeline, which will wrap
165
- the pipeline execution, allowing you to record performance metrics.
205
+ the pipeline execution, allowing you to record performance metrics. The block
206
+ receives the pipeline options as keyword arguments (including `:destination`
207
+ when one was given), and the pipeline must be executed by calling the yielded
208
+ block.
166
209
 
167
210
  ```rb
168
211
  pipeline = ImageProcessing::Vips.instrumenter do |**options, &processing|
@@ -170,7 +213,7 @@ pipeline = ImageProcessing::Vips.instrumenter do |**options, &processing|
170
213
  options[:loader] #=> { fail: true }
171
214
  options[:saver] #=> { quality: 85 }
172
215
  options[:format] #=> "png"
173
- options[:operations] #=> [[:resize_to_limit, 500, 500], [:flip, [:horizontal]]]
216
+ options[:operations] #=> [[:resize_to_limit, [500, 500]], [:flip, [:horizontal]]]
174
217
  options[:processor] #=> ImageProcessing::Vips::Processor
175
218
 
176
219
  ActiveSupport::Notifications.instrument("process.image_processing", **options) do
@@ -214,9 +257,8 @@ The `ImageProcessing::MiniMagick` functionality was extracted from
214
257
 
215
258
  [MIT](LICENSE.txt)
216
259
 
217
- [libvips]: http://libvips.github.io/libvips/
218
- [ImageMagick]: https://www.imagemagick.org
219
- [GraphicsMagick]: http://www.graphicsmagick.org
260
+ [libvips]: https://www.libvips.org/
261
+ [ImageMagick]: https://imagemagick.org
220
262
  [`ImageProcessing::Vips`]: doc/vips.md#readme
221
263
  [`ImageProcessing::MiniMagick`]: doc/minimagick.md#readme
222
264
  [refile-mini_magick]: https://github.com/refile/refile-mini_magick
@@ -61,12 +61,13 @@ module ImageProcessing
61
61
  # #send. This is the single point every operation is finally dispatched
62
62
  # through, so enforcing the guard here closes all of those paths.
63
63
  #
64
- # Macros defined by the processor are called on the processor; anything
65
- # else is forwarded to the accumulator, but only if the accumulator's
66
- # class defines it or handles it via #method_missing. Methods inherited
64
+ # Macros defined by the processor (including ones mixed into it) are
65
+ # called on the processor; anything else is forwarded to the accumulator,
66
+ # but only if the accumulator's class (or a module mixed into it) defines
67
+ # it or handles it via #method_missing. Methods inherited
67
68
  # from elsewhere (Ruby core, or modules mixed into every object such as
68
69
  # ActiveSupport's Object#try) are rejected.
69
- if respond_to?(name) && method(name).owner <= ImageProcessing::Processor
70
+ if respond_to?(name) && ImageProcessing.allowed_method?(self, name, [ImageProcessing::Processor])
70
71
  receiver = self
71
72
  elsif ImageProcessing.allowed_method?(@accumulator, name, [self.class::ACCUMULATOR_CLASS])
72
73
  receiver = @accumulator
@@ -1,3 +1,3 @@
1
1
  module ImageProcessing
2
- VERSION = "2.2.1"
2
+ VERSION = "2.2.2"
3
3
  end
@@ -10,7 +10,9 @@ module ImageProcessing
10
10
  # Whether +name+ can be safely dispatched on +receiver+ when the name comes
11
11
  # from user input. A name is allowed if the receiver doesn't define it, in
12
12
  # which case it falls through to #method_missing and becomes an image
13
- # operation, or if it's defined by one of +allowed_owners+ (or a subclass).
13
+ # operation, or if it's defined by one of +allowed_owners+, a subclass, or a
14
+ # module mixed into either (e.g. custom macros added to a processor with
15
+ # `Processor.include(MyMacros)`).
14
16
  #
15
17
  # Any other method is rejected: Ruby core methods such as Kernel#send or
16
18
  # BasicObject#instance_eval, but also methods that other libraries mix into
@@ -22,7 +24,19 @@ module ImageProcessing
22
24
  # like private Kernel methods (e.g. -format, -print) working.
23
25
  def self.allowed_method?(receiver, name, allowed_owners)
24
26
  owner = receiver.public_method(name.to_s).owner
25
- allowed_owners.any? { |allowed_owner| owner <= allowed_owner }
27
+ allowed_owners.any? do |allowed_owner|
28
+ if allowed_owner.is_a?(Class)
29
+ # The owner comes from the receiver's method lookup, so if it's not
30
+ # inherited from the allowed class's superclasses, it's the allowed
31
+ # class, a subclass, or a module mixed into either.
32
+ receiver.is_a?(allowed_owner) && !(owner >= allowed_owner.superclass)
33
+ else
34
+ # A module such as Chainable can be extended into a Module object
35
+ # (e.g. ImageProcessing::Vips), whose lookup also includes Module's
36
+ # methods like #class_eval, so only the module itself is allowed.
37
+ owner <= allowed_owner
38
+ end
39
+ end
26
40
  rescue NameError
27
41
  true
28
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_processing
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić