image_processing 1.13.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: fa60a0e94436db0e6f672a321162282b92fff25b9acac0031d11f8e75bd46bee
4
- data.tar.gz: f6f2cc0a61658d8a3db0883b4bdf7b9ec6421d29b74ce22ca1fee5ea2ff58d94
3
+ metadata.gz: a1627bd72e94e9d3c200ee8a78c91a6d53c68c0ed139ead780c8feccd40bf3f4
4
+ data.tar.gz: e73eaf24349e390627206cce11fc1dccc2cb226cbd24f504cff8c72103f7c2b4
5
5
  SHA512:
6
- metadata.gz: 7220163f9f2572070de49f84ac4a9051433c504c44c6925660bcac162855b38920691d6e661deeeee3b2b6238f8a78cc4881dd10e539136bf02bef01ff05cca0
7
- data.tar.gz: 9b21b5d109a9e7f8b116cccbf347809a2943171e959e8c1efc9797fcc133759c34ee83148601aa3f413f7e972b12a1803b4229f2b27835c35ab745fe39b0011f
6
+ metadata.gz: 703ae2deab2b8533331c39961690888d51ddc100eb2bb5df036541ce240067e4c4ce3e59320d932fdedefc58811e01c3591c0699eaa4feef7fe065141be49d5f
7
+ data.tar.gz: 990a0eed40a6f50a76811f0250e73fd833dca1241d1cb3eb5df3d481623e5cb2a788533c266294c503dc0050d708d3219a3678dd33caee9e28901183ace5f307
data/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
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
+
15
+ ## 1.14.0 (2025-02-10)
16
+
17
+ * Add support for MiniMagick 5.x (@lukeasrodgers)
18
+
19
+ * Fix `#resize_to_cover` when dealing with EXIF orientated images (@brendon)
20
+
1
21
  ## 1.13.0 (2024-07-24)
2
22
 
3
23
  * [minimagick] Use `-append` when calling `#append` with no arguments (@janko)
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."
@@ -16,12 +16,12 @@ Gem::Specification.new do |spec|
16
16
  spec.files = Dir["README.md", "LICENSE.txt", "CHANGELOG.md", "lib/**/*.rb", "*.gemspec"]
17
17
  spec.require_paths = ["lib"]
18
18
 
19
- spec.add_dependency "mini_magick", ">= 4.9.5", "< 5"
20
- spec.add_dependency "ruby-vips", ">= 2.0.17", "< 3"
19
+ spec.metadata = { "changelog_uri" => spec.homepage + "/blob/master/CHANGELOG.md",
20
+ "rubygems_mfa_required" => "true" }
21
21
 
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "minitest", "~> 5.8"
24
24
  spec.add_development_dependency "minitest-hooks", ">= 1.4.2"
25
25
  spec.add_development_dependency "minispec-metadata"
26
- spec.add_development_dependency "dhash-vips"
26
+ spec.add_development_dependency "dhash-vips" unless RUBY_ENGINE == "jruby"
27
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,13 +1,25 @@
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
6
10
  extend Chainable
7
11
 
12
+ def self.convert_shim(&block)
13
+ if ::MiniMagick.respond_to?(:convert)
14
+ ::MiniMagick.convert(&block)
15
+ else
16
+ ::MiniMagick::Tool::Convert.new(&block)
17
+ end
18
+ end
19
+
8
20
  # Returns whether the given image file is processable.
9
21
  def self.valid_image?(file)
10
- ::MiniMagick::Tool::Convert.new do |convert|
22
+ convert_shim do |convert|
11
23
  convert << file.path
12
24
  convert << "null:"
13
25
  end
@@ -30,7 +42,7 @@ module ImageProcessing
30
42
  magick = path_or_magick
31
43
  else
32
44
  source_path = path_or_magick
33
- magick = ::MiniMagick::Tool::Convert.new
45
+ magick = ::ImageProcessing::MiniMagick.convert_shim
34
46
 
35
47
  Utils.apply_options(magick, **options)
36
48
 
@@ -112,18 +124,9 @@ module ImageProcessing
112
124
  # Overlays the specified image over the current one. Supports specifying
113
125
  # an additional mask, composite mode, direction or offset of the overlay
114
126
  # image.
115
- 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)
116
128
  return magick.composite if overlay == :none
117
129
 
118
- if options.key?(:compose)
119
- warn "[IMAGE_PROCESSING] The :compose parameter in #composite has been renamed to :mode, the :compose alias will be removed in ImageProcessing 2."
120
- mode = options[:compose]
121
- end
122
-
123
- if options.key?(:geometry)
124
- 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]`."
125
- geometry = options[:geometry]
126
- end
127
130
  geometry = "%+d%+d" % offset if offset
128
131
 
129
132
  overlay_path = convert_to_path(overlay, "overlay")
@@ -1,3 +1,3 @@
1
1
  module ImageProcessing
2
- VERSION = "1.13.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
@@ -93,7 +97,7 @@ module ImageProcessing
93
97
  # Resizes the image to cover the specified dimensions, without
94
98
  # cropping the excess.
95
99
  def resize_to_cover(width, height, **options)
96
- image = self.image.is_a?(String) ? ::Vips::Image.new_from_file(self.image) : self.image
100
+ image = self.image.is_a?(String) ? self.class.load_image(self.image) : self.image
97
101
 
98
102
  image_ratio = Rational(image.width, image.height)
99
103
  thumbnail_ratio = Rational(width, height)
@@ -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,55 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_processing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-07-24 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: mini_magick
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 4.9.5
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '5'
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: 4.9.5
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '5'
33
- - !ruby/object:Gem::Dependency
34
- name: ruby-vips
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: 2.0.17
40
- - - "<"
41
- - !ruby/object:Gem::Version
42
- version: '3'
43
- type: :runtime
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: 2.0.17
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: '3'
53
12
  - !ruby/object:Gem::Dependency
54
13
  name: rake
55
14
  requirement: !ruby/object:Gem::Requirement
@@ -143,8 +102,9 @@ files:
143
102
  homepage: https://github.com/janko/image_processing
144
103
  licenses:
145
104
  - MIT
146
- metadata: {}
147
- post_install_message:
105
+ metadata:
106
+ changelog_uri: https://github.com/janko/image_processing/blob/master/CHANGELOG.md
107
+ rubygems_mfa_required: 'true'
148
108
  rdoc_options: []
149
109
  require_paths:
150
110
  - lib
@@ -152,15 +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.5.11
163
- signing_key:
122
+ rubygems_version: 4.0.3
164
123
  specification_version: 4
165
124
  summary: High-level wrapper for processing images for the web with ImageMagick or
166
125
  libvips.