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 @@ ...@@ -2,19 +2,19 @@
source "http://rubygems.org" source "http://rubygems.org"
gem "sqlite3", "~>1.3.4"
gem "rails", "~> 2.3.12"
gem "activerecord", :require=>"active_record" gem "activerecord", :require=>"active_record"
gem "appraisal"
gem "aws-s3", :require=>"aws/s3"
gem "bundler"
gem "cocaine", "~>0.2" gem "cocaine", "~>0.2"
gem "fog" gem "rake"
gem "jruby-openssl", :platform=>:jruby gem "sprockets", "~> 2.0.0.beta.13", :require=>false
gem "shoulda"
gem "mime-types" gem "mime-types"
gem "jruby-openssl", :platform=>:jruby
gem "mocha" gem "mocha"
gem "rake" gem "bundler"
gem "fog"
gem "appraisal"
gem "aws-s3", :require=>"aws/s3"
gem "rdoc", :require=>false 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 @@ ...@@ -2,19 +2,19 @@
source "http://rubygems.org" source "http://rubygems.org"
gem "sqlite3", "~>1.3.4"
gem "rails", "~> 3.0.9"
gem "activerecord", :require=>"active_record" gem "activerecord", :require=>"active_record"
gem "appraisal"
gem "aws-s3", :require=>"aws/s3"
gem "bundler"
gem "cocaine", "~>0.2" gem "cocaine", "~>0.2"
gem "fog" gem "rake"
gem "jruby-openssl", :platform=>:jruby gem "sprockets", "~> 2.0.0.beta.13", :require=>false
gem "shoulda"
gem "mime-types" gem "mime-types"
gem "jruby-openssl", :platform=>:jruby
gem "mocha" gem "mocha"
gem "rake" gem "bundler"
gem "fog"
gem "appraisal"
gem "aws-s3", :require=>"aws/s3"
gem "rdoc", :require=>false 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 @@ ...@@ -2,19 +2,19 @@
source "http://rubygems.org" source "http://rubygems.org"
gem "sqlite3", "~>1.3.4"
gem "rails", "~> 3.1.0.rc5"
gem "activerecord", :require=>"active_record" gem "activerecord", :require=>"active_record"
gem "appraisal"
gem "aws-s3", :require=>"aws/s3"
gem "bundler"
gem "cocaine", "~>0.2" gem "cocaine", "~>0.2"
gem "fog" gem "rake"
gem "jruby-openssl", :platform=>:jruby gem "sprockets", "~> 2.0.0.beta.13", :require=>false
gem "shoulda"
gem "mime-types" gem "mime-types"
gem "jruby-openssl", :platform=>:jruby
gem "mocha" gem "mocha"
gem "rake" gem "bundler"
gem "fog"
gem "appraisal"
gem "aws-s3", :require=>"aws/s3"
gem "rdoc", :require=>false 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 ...@@ -14,14 +14,24 @@ module Paperclip
# unless specified. Thumbnail creation will raise no errors unless # unless specified. Thumbnail creation will raise no errors unless
# +whiny+ is true (which it is, by default. If +convert_options+ is # +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 # 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 super
geometry = options[:geometry] geometry = options[:geometry]
@file = file @file = file
@crop = geometry[-1,1] == '#' @crop = geometry[-1,1] == '#'
@target_geometry = Geometry.parse geometry @target_geometry = Geometry.parse(geometry)
@current_geometry = Geometry.from_file @file @current_geometry = (options[:file_geometry_parser] || Geometry).from_file(@file)
@source_file_options = options[:source_file_options] @source_file_options = options[:source_file_options]
@convert_options = options[:convert_options] @convert_options = options[:convert_options]
@whiny = options[:whiny].nil? ? true : options[:whiny] @whiny = options[:whiny].nil? ? true : options[:whiny]
......
...@@ -224,6 +224,32 @@ class ThumbnailTest < Test::Unit::TestCase ...@@ -224,6 +224,32 @@ class ThumbnailTest < Test::Unit::TestCase
assert !@thumb.transformation_command.include?("-resize") assert !@thumb.transformation_command.include?("-resize")
end end
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 end
context "A multipage PDF" do 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