Commit 3f7aee30 by Mike Burns

Abstract out the file geometry parser within Thumbnail. This makes it possible…

Abstract out the file geometry parser within Thumbnail. This makes it possible to have different cropping and scaling controls, as the papermill gem does.
parent d336c4a1
......@@ -2,19 +2,19 @@
source "http://rubygems.org"
gem "sqlite3", "~>1.3.4"
gem "rails", "~> 2.3.12"
gem "activerecord", :require=>"active_record"
gem "appraisal"
gem "aws-s3", :require=>"aws/s3"
gem "bundler"
gem "cocaine", "~>0.2"
gem "fog"
gem "jruby-openssl", :platform=>:jruby
gem "rake"
gem "sprockets", "~> 2.0.0.beta.13", :require=>false
gem "shoulda"
gem "mime-types"
gem "jruby-openssl", :platform=>:jruby
gem "mocha"
gem "rake"
gem "bundler"
gem "fog"
gem "appraisal"
gem "aws-s3", :require=>"aws/s3"
gem "rdoc", :require=>false
gem "shoulda"
gem "sqlite3", "~>1.3.4"
gem "sprockets", "~> 2.0.0.beta.13", :require=>false
gem "rails", "~> 2.3.12"
......@@ -2,19 +2,19 @@
source "http://rubygems.org"
gem "sqlite3", "~>1.3.4"
gem "rails", "~> 3.0.9"
gem "activerecord", :require=>"active_record"
gem "appraisal"
gem "aws-s3", :require=>"aws/s3"
gem "bundler"
gem "cocaine", "~>0.2"
gem "fog"
gem "jruby-openssl", :platform=>:jruby
gem "rake"
gem "sprockets", "~> 2.0.0.beta.13", :require=>false
gem "shoulda"
gem "mime-types"
gem "jruby-openssl", :platform=>:jruby
gem "mocha"
gem "rake"
gem "bundler"
gem "fog"
gem "appraisal"
gem "aws-s3", :require=>"aws/s3"
gem "rdoc", :require=>false
gem "shoulda"
gem "sqlite3", "~>1.3.4"
gem "sprockets", "~> 2.0.0.beta.13", :require=>false
gem "rails", "~> 3.0.9"
......@@ -2,19 +2,19 @@
source "http://rubygems.org"
gem "sqlite3", "~>1.3.4"
gem "rails", "~> 3.1.0.rc5"
gem "activerecord", :require=>"active_record"
gem "appraisal"
gem "aws-s3", :require=>"aws/s3"
gem "bundler"
gem "cocaine", "~>0.2"
gem "fog"
gem "jruby-openssl", :platform=>:jruby
gem "rake"
gem "sprockets", "~> 2.0.0.beta.13", :require=>false
gem "shoulda"
gem "mime-types"
gem "jruby-openssl", :platform=>:jruby
gem "mocha"
gem "rake"
gem "bundler"
gem "fog"
gem "appraisal"
gem "aws-s3", :require=>"aws/s3"
gem "rdoc", :require=>false
gem "shoulda"
gem "sqlite3", "~>1.3.4"
gem "sprockets", "~> 2.0.0.beta.13", :require=>false
gem "rails", "~> 3.1.0.rc5"
......@@ -14,14 +14,24 @@ module Paperclip
# unless specified. Thumbnail creation will raise no errors unless
# +whiny+ is true (which it is, by default. If +convert_options+ is
# set, the options will be appended to the convert command upon image conversion
def initialize file, options = {}, attachment = nil
#
# Options include:
#
# +geometry+ - the desired width and height of the thumbnail
# +file_geometry_parser+ - an object with a method named +from_file+ that takes an image file and produces its geometry. Defaults to Paperclip::Geometry
# +source_file_options+ - flags passed to the +convert+ command that influence how the source file is read
# +convert_options+ - flags passed to the +convert+ command that influence how the image is processed
# +whiny+ - whether to raise an error when processing fails. Defaults to true.
# +format+ - the desired filename extension
# +animated+ - whether to merge all the layers in the image. Defaults to true.
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
@target_geometry = Geometry.parse(geometry)
@current_geometry = (options[:file_geometry_parser] || Geometry).from_file(@file)
@source_file_options = options[:source_file_options]
@convert_options = options[:convert_options]
@whiny = options[:whiny].nil? ? true : options[:whiny]
......
......@@ -224,6 +224,32 @@ class ThumbnailTest < Test::Unit::TestCase
assert !@thumb.transformation_command.include?("-resize")
end
end
context "passing a custom geometry parser" do
should "produce the appropriate transformation_command" do
GeoParser = Class.new do
def self.from_file(file)
new
end
def transformation_to(target, should_crop)
["SCALE", "CROP"]
end
end
thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50", :file_geometry_parser => GeoParser)
transformation_command = thumb.transformation_command
assert transformation_command.include?('-crop'),
%{expected #{transformation_command.inspect} to include '-crop'}
assert transformation_command.include?('"CROP"'),
%{expected #{transformation_command.inspect} to include '"CROP"'}
assert transformation_command.include?('-resize'),
%{expected #{transformation_command.inspect} to include '-resize'}
assert transformation_command.include?('"SCALE"'),
%{expected #{transformation_command.inspect} to include '"SCALE"'}
end
end
end
context "A multipage PDF" do
......
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