diff --git a/lib/image_processing/mini_magick.rb b/lib/image_processing/mini_magick.rb index a577397..24b9efa 100644 --- a/lib/image_processing/mini_magick.rb +++ b/lib/image_processing/mini_magick.rb @@ -5,18 +5,19 @@ module ImageProcessing module MiniMagick extend Chainable - # Returns whether the given image file is processable. - def self.valid_image?(file) + def self.convert_shim(&block) if ::MiniMagick.respond_to?(:convert) - ::MiniMagick.convert do |convert| - convert << file.path - convert << "null:" - end + ::MiniMagick.convert(&block) else - ::MiniMagick::Tool::Convert.new do |convert| - convert << file.path - convert << "null:" - end + ::MiniMagick::Tool::Convert.new(&block) + end + end + + # Returns whether the given image file is processable. + def self.valid_image?(file) + convert_shim do |convert| + convert << file.path + convert << "null:" end true rescue ::MiniMagick::Error @@ -37,7 +38,7 @@ def self.load_image(path_or_magick, loader: nil, page: nil, geometry: nil, auto_ magick = path_or_magick else source_path = path_or_magick - magick = ::MiniMagick::Tool::Convert.new + magick = ::ImageProcessing::MiniMagick.convert_shim Utils.apply_options(magick, **options) diff --git a/test/mini_magick_test.rb b/test/mini_magick_test.rb index b899b89..36f2c24 100644 --- a/test/mini_magick_test.rb +++ b/test/mini_magick_test.rb @@ -14,7 +14,7 @@ it "applies imagemagick operations" do actual = ImageProcessing::MiniMagick.flip.call(@portrait) expected = Tempfile.new(["result", ".jpg"], binmode: true).tap do |tempfile| - MiniMagick::Tool::Convert.new do |cmd| + ImageProcessing::MiniMagick.convert_shim do |cmd| cmd << @portrait.path cmd.flip cmd << tempfile.path @@ -37,7 +37,7 @@ it "applies macro operations" do actual = ImageProcessing::MiniMagick.resize_to_limit(400, 400).call(@portrait) expected = Tempfile.new(["result", ".jpg"], binmode: true).tap do |tempfile| - MiniMagick::Tool::Convert.new do |cmd| + ImageProcessing::MiniMagick.convert_shim do |cmd| cmd << @portrait.path cmd.resize("400x400") cmd << tempfile.path @@ -55,7 +55,7 @@ it "accepts page" do tiff = Tempfile.new(["file", ".tiff"]) - MiniMagick::Tool::Convert.new do |convert| + ImageProcessing::MiniMagick.convert_shim do |convert| convert.merge! [@portrait.path, @portrait.path, @portrait.path] convert << tiff.path end @@ -70,7 +70,7 @@ it "disallows split layers by default" do tiff = Tempfile.new(["file", ".tiff"]) - MiniMagick::Tool::Convert.new do |convert| + ImageProcessing::MiniMagick.convert_shim do |convert| convert.merge! [@portrait.path, @portrait.path, @portrait.path] convert << tiff.path end @@ -168,7 +168,7 @@ end it "accepts magick object as source" do - magick = MiniMagick::Tool::Convert.new + magick = ImageProcessing::MiniMagick.convert_shim magick << fixture_image("rotated.jpg").path result = ImageProcessing::MiniMagick.source(magick).call assert_dimensions [600, 800], result @@ -568,7 +568,7 @@ it "appends CLI arguments" do actual = ImageProcessing::MiniMagick.append("-resize", "400x400").call(@portrait) expected = Tempfile.new(["result", ".jpg"], binmode: true).tap do |tempfile| - MiniMagick::Tool::Convert.new do |cmd| + ImageProcessing::MiniMagick.convert_shim do |cmd| cmd << @portrait.path cmd.resize("400x400") cmd << tempfile.path