image_processing 1.14.0 → 2.0.0

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: 613676364c0ba04b655a087a89296cec4604c8f362809ada23d984538f9e962b
4
- data.tar.gz: 77a768424b857418d131257ce2c539715aa69999da7e78319255d9eee3f68157
3
+ metadata.gz: a1627bd72e94e9d3c200ee8a78c91a6d53c68c0ed139ead780c8feccd40bf3f4
4
+ data.tar.gz: e73eaf24349e390627206cce11fc1dccc2cb226cbd24f504cff8c72103f7c2b4
5
5
  SHA512:
6
- metadata.gz: ff2e1a9bf128d872ad2c5663525c4e970e8b18457f2b4f0a50588a9f33c736b0ef46a3fb4bd10638be5a276e9aa8bacbae09c9685b954416902de3687a3b2181
7
- data.tar.gz: c7efff88134c14c44001ea99ed7632ecc86b93bd3afe5e933cfdc8cb2d57a82fc69333192777ac17cdf9e5bf5ef15e012c17e6c7dffbd7124ed58d765e4bff4b
6
+ metadata.gz: 703ae2deab2b8533331c39961690888d51ddc100eb2bb5df036541ce240067e4c4ce3e59320d932fdedefc58811e01c3591c0699eaa4feef7fe065141be49d5f
7
+ data.tar.gz: 990a0eed40a6f50a76811f0250e73fd833dca1241d1cb3eb5df3d481623e5cb2a788533c266294c503dc0050d708d3219a3678dd33caee9e28901183ace5f307
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 2.0.0 (2026-05-20)
2
+
3
+ * `mini_magick`/`ruby-vips` are now soft dependencies and need to be manually added to the Gemfile (@janko)
4
+
5
+ * Avoid remote shell execution vulnerability in `#apply` when arguments are coming from user input (@janko)
6
+
7
+ * [vips] Unfuzzed loaders are now blocked by default (@janko)
8
+
9
+ * [vips] Sharpening after resize has been disabled by default (@janko)
10
+
11
+ * [minimagick] Remove deprecated `:compose` and `:geometry` keyword arguments for `#composite` (@janko)
12
+
13
+ * Ruby 3.0+ is now required (@janko)
14
+
1
15
  ## 1.14.0 (2025-02-10)
2
16
 
3
17
  * Add support for MiniMagick 5.x (@lukeasrodgers)
data/README.md CHANGED
@@ -3,11 +3,10 @@
3
3
  Provides higher-level image processing helpers that are commonly needed
4
4
  when handling image uploads.
5
5
 
6
- This gem can process images with either [ImageMagick]/[GraphicsMagick] or
7
- [libvips] libraries. ImageMagick is a good default choice, especially if you
8
- are migrating from another gem or library that uses ImageMagick. Libvips is a
9
- newer library that can process images [very rapidly][libvips performance]
10
- (often multiple times faster than ImageMagick).
6
+ This gem can process images with [ImageMagick] or [libvips]. ImageMagick is a
7
+ good default choice, especially if you are migrating from another gem or library
8
+ that uses ImageMagick. Libvips is a newer library that can process images [very
9
+ rapidly][libvips performance] (often multiple times faster than ImageMagick).
11
10
 
12
11
 
13
12
  ## Goal
@@ -16,7 +15,7 @@ The goal of this project is to have a single gem that contains all the
16
15
  helper methods needed to resize and process images.
17
16
 
18
17
  Currently, existing attachment gems (like Paperclip, CarrierWave, Refile,
19
- Dragonfly, ActiveStorage, and others) implement their own custom image
18
+ Dragonfly, Active Storage, and others) implement their own custom image
20
19
  helper methods. But why? That's not very DRY, is it?
21
20
 
22
21
  Let's be honest. Image processing is a dark, mysterious art. So we want to
@@ -32,19 +31,23 @@ how to resize and process images.
32
31
  In a Mac terminal:
33
32
 
34
33
  ```sh
35
- $ brew install imagemagick vips
34
+ $ brew install imagemagick # if using ImageMagick
35
+ $ brew install vips # if using libvips
36
36
  ```
37
37
 
38
38
  In a debian/ubuntu terminal:
39
39
 
40
40
  ```sh
41
- $ sudo apt install imagemagick libvips
41
+ $ sudo apt install imagemagick # if using ImageMagick
42
+ $ sudo apt install libvips # if using libvips
42
43
  ```
43
44
 
44
- 2. Add the gem to your Gemfile:
45
+ 2. Add the gem(s) to your Gemfile:
45
46
 
46
47
  ```rb
47
- gem "image_processing", "~> 1.0"
48
+ gem "image_processing", "~> 2.0"
49
+ gem "mini_magick", "~> 5.0" # if using ImageMagick
50
+ gem "ruby-vips", "~> 2.0" # if using libvips
48
51
  ```
49
52
 
50
53
 
@@ -66,7 +69,7 @@ processed = ImageProcessing::MiniMagick
66
69
  processed #=> #<Tempfile:/var/folders/.../image_processing20180316-18446-1j247h6.png>
67
70
  ```
68
71
 
69
- This allows easy branching when generating multiple derivates:
72
+ This allows easy branching when generating multiple derivatives:
70
73
 
71
74
  ```rb
72
75
  require "image_processing/vips"
@@ -187,22 +190,9 @@ pipeline
187
190
 
188
191
  ## Contributing
189
192
 
190
- Our test suite requires both `imagemagick` and `libvips` libraries to be installed.
193
+ Our test suite requires both `imagemagick` and `libvips` libraries to be installed. Afterwards you can run tests with:
191
194
 
192
- In a Mac terminal:
193
-
194
- ```
195
- $ brew install imagemagick vips
196
- ```
197
-
198
- In a debian/ubuntu terminal:
199
- ```shell
200
- sudo apt install imagemagick libvips
201
- ```
202
-
203
- Afterwards you can run tests with
204
-
205
- ```
195
+ ```sh
206
196
  $ bundle exec rake test
207
197
  ```
208
198
 
@@ -4,7 +4,7 @@ Gem::Specification.new do |spec|
4
4
  spec.name = "image_processing"
5
5
  spec.version = ImageProcessing::VERSION
6
6
 
7
- spec.required_ruby_version = ">= 2.3"
7
+ spec.required_ruby_version = ">= 3.0"
8
8
 
9
9
  spec.summary = "High-level wrapper for processing images for the web with ImageMagick or libvips."
10
10
  spec.description = "High-level wrapper for processing images for the web with ImageMagick or libvips."
@@ -19,12 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.metadata = { "changelog_uri" => spec.homepage + "/blob/master/CHANGELOG.md",
20
20
  "rubygems_mfa_required" => "true" }
21
21
 
22
- spec.add_dependency "mini_magick", ">= 4.9.5", "< 6"
23
- spec.add_dependency "ruby-vips", ">= 2.0.17", "< 3"
24
-
25
22
  spec.add_development_dependency "rake"
26
23
  spec.add_development_dependency "minitest", "~> 5.8"
27
24
  spec.add_development_dependency "minitest-hooks", ">= 1.4.2"
28
25
  spec.add_development_dependency "minispec-metadata"
29
- spec.add_development_dependency "dhash-vips"
26
+ spec.add_development_dependency "dhash-vips" unless RUBY_ENGINE == "jruby"
30
27
  end
@@ -33,6 +33,10 @@ module ImageProcessing
33
33
  # .apply([[:resize_to_limit, [400, 400]], [:strip, true])
34
34
  def apply(operations)
35
35
  operations.inject(self) do |builder, (name, argument)|
36
+ if invalid_operation?(name)
37
+ fail ArgumentError, "#{name.inspect} is not a valid ImageProcessing operation"
38
+ end
39
+
36
40
  if argument == true || argument == nil
37
41
  builder.public_send(name)
38
42
  elsif argument.is_a?(Array)
@@ -81,11 +85,22 @@ module ImageProcessing
81
85
 
82
86
  private
83
87
 
88
+ # This prevents calling unsafe Ruby core methods such as `Kernel#system`,
89
+ # which would allow for remote shell execution.
90
+ def invalid_operation?(name)
91
+ return true if name.end_with?("!")
92
+
93
+ owner = method(name).owner
94
+ [BasicObject, Kernel, Object, Module].include?(owner)
95
+ rescue NameError
96
+ false
97
+ end
98
+
84
99
  # Assume that any unknown method names an operation supported by the
85
100
  # processor. Add a bang ("!") if you want processing to be performed.
86
101
  def method_missing(name, *args, &block)
87
102
  return super if name.to_s.end_with?("?")
88
- return send(name.to_s.chomp("!"), *args, &block).call if name.to_s.end_with?("!")
103
+ return public_send(name.to_s.chomp("!"), *args, &block).call if name.to_s.end_with?("!")
89
104
 
90
105
  operation(name, *args, &block)
91
106
  end
@@ -1,5 +1,9 @@
1
- require "mini_magick"
2
1
  require "image_processing"
2
+ begin
3
+ require "mini_magick"
4
+ rescue LoadError
5
+ fail ImageProcessing::Error, "ImageProcessing::MiniMagick requires the mini_magick gem. Please add `gem \"mini_magick\", \"~> 5.0\"` to your Gemfile."
6
+ end
3
7
 
4
8
  module ImageProcessing
5
9
  module MiniMagick
@@ -120,18 +124,9 @@ module ImageProcessing
120
124
  # Overlays the specified image over the current one. Supports specifying
121
125
  # an additional mask, composite mode, direction or offset of the overlay
122
126
  # image.
123
- def composite(overlay = :none, mask: nil, mode: nil, gravity: nil, offset: nil, args: nil, **options, &block)
127
+ def composite(overlay = :none, mask: nil, mode: nil, gravity: nil, offset: nil, args: nil, &block)
124
128
  return magick.composite if overlay == :none
125
129
 
126
- if options.key?(:compose)
127
- warn "[IMAGE_PROCESSING] The :compose parameter in #composite has been renamed to :mode, the :compose alias will be removed in ImageProcessing 2."
128
- mode = options[:compose]
129
- end
130
-
131
- if options.key?(:geometry)
132
- warn "[IMAGE_PROCESSING] The :geometry parameter in #composite has been deprecated and will be removed in ImageProcessing 2. Use :offset instead, e.g. `geometry: \"+10+15\"` should be replaced with `offset: [10, 15]`."
133
- geometry = options[:geometry]
134
- end
135
130
  geometry = "%+d%+d" % offset if offset
136
131
 
137
132
  overlay_path = convert_to_path(overlay, "overlay")
@@ -1,3 +1,3 @@
1
1
  module ImageProcessing
2
- VERSION = "1.14.0"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,7 +1,11 @@
1
- require "vips"
2
1
  require "image_processing"
2
+ begin
3
+ require "vips"
4
+ rescue LoadError
5
+ fail ImageProcessing::Error, "ImageProcessing::Vips requires the ruby-vips gem. Please add `gem \"ruby-vips\", \"~> 2.0\"` to your Gemfile."
6
+ end
3
7
 
4
- fail "image_processing/vips requires libvips 8.6+" unless Vips.at_least_libvips?(8, 6)
8
+ Vips.block_untrusted(true) if Vips.respond_to?(:block_untrusted) && !ENV["VIPS_BLOCK_UNTRUSTED"]
5
9
 
6
10
  module ImageProcessing
7
11
  module Vips
@@ -155,7 +159,7 @@ module ImageProcessing
155
159
 
156
160
  # Resizes the image according to the specified parameters, and sharpens
157
161
  # the resulting thumbnail.
158
- def thumbnail(width, height, sharpen: SHARPEN_MASK, **options)
162
+ def thumbnail(width, height, sharpen: nil, **options)
159
163
  if self.image.is_a?(String) # path
160
164
  # resize on load
161
165
  image = ::Vips::Image.thumbnail(self.image, width, height: height, **options)
@@ -167,7 +171,11 @@ module ImageProcessing
167
171
  image = self.image.thumbnail_image(width, height: height, **options)
168
172
  end
169
173
 
170
- image = image.conv(sharpen, precision: :integer) if sharpen
174
+ if sharpen
175
+ sharpen_mask = sharpen.is_a?(TrueClass) ? SHARPEN_MASK : sharpen
176
+ image = image.conv(sharpen_mask, precision: :integer)
177
+ end
178
+
171
179
  image
172
180
  end
173
181
 
@@ -7,6 +7,6 @@ require "image_processing/version"
7
7
  module ImageProcessing
8
8
  Error = Class.new(StandardError)
9
9
 
10
- autoload :MiniMagick, 'image_processing/mini_magick'
11
- autoload :Vips, 'image_processing/vips'
10
+ autoload :MiniMagick, "image_processing/mini_magick"
11
+ autoload :Vips, "image_processing/vips"
12
12
  end
metadata CHANGED
@@ -1,54 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_processing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-10 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
- - !ruby/object:Gem::Dependency
13
- name: mini_magick
14
- requirement: !ruby/object:Gem::Requirement
15
- requirements:
16
- - - ">="
17
- - !ruby/object:Gem::Version
18
- version: 4.9.5
19
- - - "<"
20
- - !ruby/object:Gem::Version
21
- version: '6'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- version: 4.9.5
29
- - - "<"
30
- - !ruby/object:Gem::Version
31
- version: '6'
32
- - !ruby/object:Gem::Dependency
33
- name: ruby-vips
34
- requirement: !ruby/object:Gem::Requirement
35
- requirements:
36
- - - ">="
37
- - !ruby/object:Gem::Version
38
- version: 2.0.17
39
- - - "<"
40
- - !ruby/object:Gem::Version
41
- version: '3'
42
- type: :runtime
43
- prerelease: false
44
- version_requirements: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: 2.0.17
49
- - - "<"
50
- - !ruby/object:Gem::Version
51
- version: '3'
52
12
  - !ruby/object:Gem::Dependency
53
13
  name: rake
54
14
  requirement: !ruby/object:Gem::Requirement
@@ -152,14 +112,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
112
  requirements:
153
113
  - - ">="
154
114
  - !ruby/object:Gem::Version
155
- version: '2.3'
115
+ version: '3.0'
156
116
  required_rubygems_version: !ruby/object:Gem::Requirement
157
117
  requirements:
158
118
  - - ">="
159
119
  - !ruby/object:Gem::Version
160
120
  version: '0'
161
121
  requirements: []
162
- rubygems_version: 3.6.2
122
+ rubygems_version: 4.0.3
163
123
  specification_version: 4
164
124
  summary: High-level wrapper for processing images for the web with ImageMagick or
165
125
  libvips.