Permalink
Browse files

Memoize result of identify command in order to avoid multiple calls t…

…o ImageMagick
  • Loading branch information...
1 parent c5f2b14 commit fe19916633fcd10d5429066bc60cfb2ca5992e22 @adamniedzielski adamniedzielski committed with jyurek Jan 28, 2014
Showing with 4 additions and 1 deletion.
  1. +4 −1 lib/paperclip/thumbnail.rb
@@ -109,7 +109,10 @@ def animated?
# 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
+ 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
raise Paperclip::Error, "There was an error running `identify` for #{@basename}" if @whiny
rescue Cocaine::CommandNotFoundError => e

0 comments on commit fe19916

Please sign in to comment.