Skip to content
Browse files

Add an option to ThumbnailProcessor to override animated thumbnail ge…

…neration.

Closes #515
  • Loading branch information...
1 parent 489df17 commit f5851f1d2d1d55439ac49071771246e0c76e87db @sikachu sikachu committed Jul 15, 2011
Showing with 24 additions and 4 deletions.
  1. +2 −2 lib/paperclip/style.rb
  2. +4 −2 lib/paperclip/thumbnail.rb
  3. +18 −0 test/thumbnail_test.rb
View
4 lib/paperclip/style.rb
@@ -72,15 +72,15 @@ def processor_options
# Supports getting and setting style properties with hash notation to ensure backwards-compatibility
# eg. @attachment.styles[:large][:geometry]@ will still work
def [](key)
- if [:name, :convert_options, :whiny, :processors, :geometry, :format].include?(key)
+ if [:name, :convert_options, :whiny, :processors, :geometry, :format, :animated].include?(key)
send(key)
elsif defined? @other_args[key]
@other_args[key]
end
end
def []=(key, value)
- if [:name, :convert_options, :whiny, :processors, :geometry, :format].include?(key)
+ if [:name, :convert_options, :whiny, :processors, :geometry, :format, :animated].include?(key)
send("#{key}=".intern, value)
else
@other_args[key] = value
View
6 lib/paperclip/thumbnail.rb
@@ -2,7 +2,8 @@ module Paperclip
# Handles thumbnailing images that are uploaded.
class Thumbnail < Processor
- attr_accessor :current_geometry, :target_geometry, :format, :whiny, :convert_options, :source_file_options
+ attr_accessor :current_geometry, :target_geometry, :format, :whiny, :convert_options,
+ :source_file_options, :animated
# List of formats that we need to preserve animation
ANIMATED_FORMATS = %w(gif)
@@ -25,6 +26,7 @@ def initialize file, options = {}, attachment = nil
@convert_options = options[:convert_options]
@whiny = options[:whiny].nil? ? true : options[:whiny]
@format = options[:format]
+ @animated = options[:animated].nil? ? true : options[:animated]
@source_file_options = @source_file_options.split(/\s+/) if @source_file_options.respond_to?(:split)
@convert_options = @convert_options.split(/\s+/) if @convert_options.respond_to?(:split)
@@ -86,7 +88,7 @@ def transformation_command
# Return true if the format is animated
def animated?
- ANIMATED_FORMATS.include?(@current_format[1..-1]) && (ANIMATED_FORMATS.include?(@format.to_s) || @format.blank?)
+ @animated && ANIMATED_FORMATS.include?(@current_format[1..-1]) && (ANIMATED_FORMATS.include?(@format.to_s) || @format.blank?)
end
end
end
View
18 test/thumbnail_test.rb
@@ -310,5 +310,23 @@ class ThumbnailTest < Test::Unit::TestCase
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)
+ end
+
+ should "output the gif format" do
+ dst = @thumb.make
+ cmd = %Q[identify "#{dst.path}"]
+ assert_match /GIF/, `#{cmd}`.chomp
+ end
+
+ should "create the single frame thumbnail when sent #make" do
+ dst = @thumb.make
+ cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
+ assert_equal "50x50", `#{cmd}`.chomp
+ end
+ end
end
end

0 comments on commit f5851f1

Please sign in to comment.
Something went wrong with that request. Please try again.