Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add an option to ThumbnailProcessor to override animated thumbnail ge…

…neration.

Closes #515
  • Loading branch information...
commit f5851f1d2d1d55439ac49071771246e0c76e87db 1 parent 489df17
@sikachu sikachu authored
View
4 lib/paperclip/style.rb
@@ -72,7 +72,7 @@ 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]
@@ -80,7 +80,7 @@ def [](key)
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
Please sign in to comment.
Something went wrong with that request. Please try again.