Skip to content

Commit

Permalink
Stop using MiniMagick::Image#run_command
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibuya committed Nov 23, 2024
1 parent 61c2732 commit e640ea7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/carrierwave/processing/mini_magick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def manipulate!
image = yield(image)
FileUtils.mv image.path, current_path

image.run_command("identify", current_path)
::MiniMagick::Image.new(current_path).identify
rescue ::MiniMagick::Error, ::MiniMagick::Invalid => e
raise e if e.message =~ /(You must have .+ installed|is not installed|executable not found)/
message = I18n.translate(:"errors.messages.processing_error")
Expand Down
8 changes: 8 additions & 0 deletions spec/processing/mini_magick_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@
expect(instance).to be_format('png')
end

it "returns the result of #identify on the manipulated image" do
expect(
instance.manipulate! do |image|
image.format('png')
end
).to include 'landscape_copy.jpg PNG 640x480'
end

context "on failing to find ImageMagick/GraphicsMagick" do
before do
MiniMagick.remove_instance_variable(:@processor) if MiniMagick.instance_variable_defined?(:@processor)
Expand Down
8 changes: 6 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ def change_and_enforce_available_locales(locale, available_locales, &block)

module ManipulationHelpers
def color_of_pixel(path, x, y)
image = ::MiniMagick::Image.open(path)
image.run_command("convert", "#{image.path}[1x1+#{x}+#{y}]", "-depth", "8", "txt:").split("\n")[1]
convert = ::MiniMagick::Tool::Convert.new
convert << path
convert.crop("1x1+#{x}+#{y}")
convert.depth(8)
convert << "txt:"
convert.call.split("\n")[1]
end
end

Expand Down

0 comments on commit e640ea7

Please sign in to comment.