Commit 2826cdb7 by Jon Yurek

Added options to the source file when processing thumbnails

parent 121609fa
......@@ -2,7 +2,7 @@ module Paperclip
# Handles thumbnailing images that are uploaded.
class Thumbnail < Processor
attr_accessor :current_geometry, :target_geometry, :format, :whiny, :convert_options
attr_accessor :current_geometry, :target_geometry, :format, :whiny, :convert_options, :source_file_options
# Creates a Thumbnail object set to work on the +file+ given. It
# will attempt to transform the image into one defined by +target_geometry+
......@@ -12,17 +12,18 @@ module Paperclip
# set, the options will be appended to the convert command upon image conversion
def initialize file, options = {}, attachment = nil
super
geometry = options[:geometry]
@file = file
@crop = geometry[-1,1] == '#'
@target_geometry = Geometry.parse geometry
@current_geometry = Geometry.from_file @file
@convert_options = options[:convert_options]
@whiny = options[:whiny].nil? ? true : options[:whiny]
@format = options[:format]
geometry = options[:geometry]
@file = file
@crop = geometry[-1,1] == '#'
@target_geometry = Geometry.parse geometry
@current_geometry = Geometry.from_file @file
@source_file_options = options[:source_file_options]
@convert_options = options[:convert_options]
@whiny = options[:whiny].nil? ? true : options[:whiny]
@format = options[:format]
@current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format)
@current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format)
end
# Returns true if the +target_geometry+ is meant to crop.
......@@ -43,6 +44,7 @@ module Paperclip
dst.binmode
command = <<-end_command
#{ source_file_options }
"#{ File.expand_path(src.path) }[0]"
#{ transformation_command }
"#{ File.expand_path(dst.path) }"
......
......@@ -103,6 +103,44 @@ class ThumbnailTest < Test::Unit::TestCase
end
end
context "being thumbnailed with source file options set" do
setup do
@thumb = Paperclip::Thumbnail.new(@file,
:geometry => "100x50#",
:source_file_options => "-strip")
end
should "have source_file_options value set" do
assert_equal "-strip", @thumb.source_file_options
end
should "send the right command to convert when sent #make" do
Paperclip.expects(:"`").with do |arg|
arg.match %r{convert\s+-strip\s+"#{File.expand_path(@thumb.file.path)}\[0\]"\s+-resize\s+"x50"\s+-crop\s+"100x50\+114\+0"\s+\+repage\s+".*?"}
end
@thumb.make
end
should "create the thumbnail when sent #make" do
dst = @thumb.make
assert_match /100x50/, `identify "#{dst.path}"`
end
context "redefined to have bad source_file_options setting" do
setup do
@thumb = Paperclip::Thumbnail.new(@file,
:geometry => "100x50#",
:source_file_options => "-this-aint-no-option")
end
should "error when trying to create the thumbnail" do
assert_raises(Paperclip::PaperclipError) do
@thumb.make
end
end
end
end
context "being thumbnailed with convert options set" do
setup do
@thumb = Paperclip::Thumbnail.new(@file,
......
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