Permalink
Browse files

#47: Multipage PDFs fixed by Pete Deffendol

  • Loading branch information...
1 parent 8a43c13 commit 06f9b99e5f00627b7fe1377db0dc996a3eada655 @jyurek jyurek committed Jan 8, 2009
Showing with 34 additions and 1 deletion.
  1. +1 −1 lib/paperclip/geometry.rb
  2. BIN test/fixtures/twopage.pdf
  3. +33 −0 test/thumbnail_test.rb
@@ -16,7 +16,7 @@ def initialize width = nil, height = nil, modifier = nil
def self.from_file file
file = file.path if file.respond_to? "path"
geometry = begin
- Paperclip.run("identify", %Q[-format "%wx%h" "#{file}"])
+ Paperclip.run("identify", %Q[-format "%wx%h" "#{file}"[0]])
rescue PaperclipCommandLineError
""
end
View
Binary file not shown.
View
@@ -141,4 +141,37 @@ class ThumbnailTest < Test::Unit::TestCase
end
end
end
+
+ context "A multipage PDF" do
+ setup do
+ @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "twopage.pdf"), 'rb')
+ end
+
+ teardown { @file.close }
+
+ should "start with two pages with dimensions 612x792" do
+ cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
+ assert_equal "612x792"*2, `#{cmd}`.chomp
+ end
+
+ context "being thumbnailed at 100x100 with cropping" do
+ setup do
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x100#", :format => :png)
+ end
+
+ should "report its correct current and target geometries" do
+ assert_equal "100x100#", @thumb.target_geometry.to_s
+ assert_equal "612x792", @thumb.current_geometry.to_s
+ end
+
+ should "report its correct format" do
+ assert_equal :png, @thumb.format
+ end
+
+ should "create the thumbnail when sent #make" do
+ dst = @thumb.make
+ assert_match /100x100/, `identify "#{dst.path}"`
+ end
+ end
+ end
end

0 comments on commit 06f9b99

Please sign in to comment.