Commit c54708f2 by Juanjo Bazán Committed by Mike Burns

Identify animated formats using ImageMagick.

parent cdfc4cfa
......@@ -98,7 +98,16 @@ module Paperclip
# Return true if the format is animated
def animated?
@animated && ANIMATED_FORMATS.include?(@current_format[1..-1]) && (ANIMATED_FORMATS.include?(@format.to_s) || @format.blank?)
@animated && (ANIMATED_FORMATS.include?(@format.to_s) || @format.blank?) && identified_as_animated?
end
# Return true if ImageMagick's +identify+ returns an animated format
def identified_as_animated?
ANIMATED_FORMATS.include? identify("-format %m :file", :file => "#{@file.path}[0]").to_s.downcase.strip
rescue Cocaine::ExitStatusError => e
raise Paperclip::Error, "There was an error running `identify` for #{@basename}" if @whiny
rescue Cocaine::CommandNotFoundError => e
raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `identify` command. Please install ImageMagick.")
end
end
end
......@@ -234,6 +234,17 @@ class ThumbnailTest < Test::Unit::TestCase
end
end
context "being thumbnailed with default animated option (true)" do
should "call identify to check for animated images when sent #make" do
thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50#")
thumb.expects(:identify).at_least_once.with do |*arg|
arg[0] == '-format %m :file' &&
arg[1][:file] == "#{File.expand_path(thumb.file.path)}[0]"
end
thumb.make
end
end
context "passing a custom file geometry parser" do
teardown do
self.class.send(:remove_const, :GeoParser)
......@@ -380,6 +391,40 @@ class ThumbnailTest < Test::Unit::TestCase
end
end
context "with unidentified source format" do
setup do
@unidentified_file = File.new(fixture_file("animated.unknown"), 'rb')
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "60x60")
end
should "create the 12 frames thumbnail when sent #make" do
dst = @thumb.make
cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
assert_equal "60x60"*12, `#{cmd}`.chomp
end
should "use the -coalesce option" do
assert_equal @thumb.transformation_command.first, "-coalesce"
end
end
context "with no source format" do
setup do
@unidentified_file = File.new(fixture_file("animated"), 'rb')
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "70x70")
end
should "create the 12 frames thumbnail when sent #make" do
dst = @thumb.make
cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
assert_equal "70x70"*12, `#{cmd}`.chomp
end
should "use the -coalesce option" do
assert_equal @thumb.transformation_command.first, "-coalesce"
end
end
context "with animated option set to false" do
setup do
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50", :animated => false)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment