Skip to content

Commit ba30289

Browse files
Upgrade minimagick 5 (#132)
* Add gemfiles for multi-gem version testing * Permit mini_magic v5 in gemspec * Support valid image check for minimagic5 * Use a shim to simplify support for minimagick 4 and 5
1 parent 8490530 commit ba30289

File tree

6 files changed

+32
-9
lines changed

6 files changed

+32
-9
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Gemfile.lock
2+
gemfiles/*.lock
23
pkg/
34
.DS_Store

gemfiles/mini_magick4.gemfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec :path => '../'
4+
5+
gem 'pry'
6+
7+
gem 'mini_magick', '~> 4.9'

gemfiles/mini_magick5.gemfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec :path => '../'
4+
5+
gem 'pry'
6+
7+
gem 'mini_magick', '~> 5.0'

image_processing.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
1919
spec.metadata = { "changelog_uri" => spec.homepage + "/blob/master/CHANGELOG.md",
2020
"rubygems_mfa_required" => "true" }
2121

22-
spec.add_dependency "mini_magick", ">= 4.9.5", "< 5"
22+
spec.add_dependency "mini_magick", ">= 4.9.5", "< 6"
2323
spec.add_dependency "ruby-vips", ">= 2.0.17", "< 3"
2424

2525
spec.add_development_dependency "rake"

lib/image_processing/mini_magick.rb

+10-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ module ImageProcessing
55
module MiniMagick
66
extend Chainable
77

8+
def self.convert_shim(&block)
9+
if ::MiniMagick.respond_to?(:convert)
10+
::MiniMagick.convert(&block)
11+
else
12+
::MiniMagick::Tool::Convert.new(&block)
13+
end
14+
end
15+
816
# Returns whether the given image file is processable.
917
def self.valid_image?(file)
10-
::MiniMagick::Tool::Convert.new do |convert|
18+
convert_shim do |convert|
1119
convert << file.path
1220
convert << "null:"
1321
end
@@ -30,7 +38,7 @@ def self.load_image(path_or_magick, loader: nil, page: nil, geometry: nil, auto_
3038
magick = path_or_magick
3139
else
3240
source_path = path_or_magick
33-
magick = ::MiniMagick::Tool::Convert.new
41+
magick = ::ImageProcessing::MiniMagick.convert_shim
3442

3543
Utils.apply_options(magick, **options)
3644

test/mini_magick_test.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
it "applies imagemagick operations" do
1515
actual = ImageProcessing::MiniMagick.flip.call(@portrait)
1616
expected = Tempfile.new(["result", ".jpg"], binmode: true).tap do |tempfile|
17-
MiniMagick::Tool::Convert.new do |cmd|
17+
ImageProcessing::MiniMagick.convert_shim do |cmd|
1818
cmd << @portrait.path
1919
cmd.flip
2020
cmd << tempfile.path
@@ -37,7 +37,7 @@
3737
it "applies macro operations" do
3838
actual = ImageProcessing::MiniMagick.resize_to_limit(400, 400).call(@portrait)
3939
expected = Tempfile.new(["result", ".jpg"], binmode: true).tap do |tempfile|
40-
MiniMagick::Tool::Convert.new do |cmd|
40+
ImageProcessing::MiniMagick.convert_shim do |cmd|
4141
cmd << @portrait.path
4242
cmd.resize("400x400")
4343
cmd << tempfile.path
@@ -55,7 +55,7 @@
5555

5656
it "accepts page" do
5757
tiff = Tempfile.new(["file", ".tiff"])
58-
MiniMagick::Tool::Convert.new do |convert|
58+
ImageProcessing::MiniMagick.convert_shim do |convert|
5959
convert.merge! [@portrait.path, @portrait.path, @portrait.path]
6060
convert << tiff.path
6161
end
@@ -70,7 +70,7 @@
7070

7171
it "disallows split layers by default" do
7272
tiff = Tempfile.new(["file", ".tiff"])
73-
MiniMagick::Tool::Convert.new do |convert|
73+
ImageProcessing::MiniMagick.convert_shim do |convert|
7474
convert.merge! [@portrait.path, @portrait.path, @portrait.path]
7575
convert << tiff.path
7676
end
@@ -168,7 +168,7 @@
168168
end
169169

170170
it "accepts magick object as source" do
171-
magick = MiniMagick::Tool::Convert.new
171+
magick = ImageProcessing::MiniMagick.convert_shim
172172
magick << fixture_image("rotated.jpg").path
173173
result = ImageProcessing::MiniMagick.source(magick).call
174174
assert_dimensions [600, 800], result
@@ -568,7 +568,7 @@
568568
it "appends CLI arguments" do
569569
actual = ImageProcessing::MiniMagick.append("-resize", "400x400").call(@portrait)
570570
expected = Tempfile.new(["result", ".jpg"], binmode: true).tap do |tempfile|
571-
MiniMagick::Tool::Convert.new do |cmd|
571+
ImageProcessing::MiniMagick.convert_shim do |cmd|
572572
cmd << @portrait.path
573573
cmd.resize("400x400")
574574
cmd << tempfile.path

0 commit comments

Comments
 (0)