Commit fe199166 by Adam Niedzielski Committed by Jon Yurek

Memoize result of identify command in order to avoid multiple calls to ImageMagick

parent c5f2b145
...@@ -109,7 +109,10 @@ module Paperclip ...@@ -109,7 +109,10 @@ module Paperclip
# Return true if ImageMagick's +identify+ returns an animated format # Return true if ImageMagick's +identify+ returns an animated format
def identified_as_animated? def identified_as_animated?
ANIMATED_FORMATS.include? identify("-format %m :file", :file => "#{@file.path}[0]").to_s.downcase.strip if @identified_as_animated.nil?
@identified_as_animated = ANIMATED_FORMATS.include? identify("-format %m :file", :file => "#{@file.path}[0]").to_s.downcase.strip
end
@identified_as_animated
rescue Cocaine::ExitStatusError => e rescue Cocaine::ExitStatusError => e
raise Paperclip::Error, "There was an error running `identify` for #{@basename}" if @whiny raise Paperclip::Error, "There was an error running `identify` for #{@basename}" if @whiny
rescue Cocaine::CommandNotFoundError => e rescue Cocaine::CommandNotFoundError => e
......
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