Permalink
Browse files

Rewind IOs passed to image(), to allow multiple embeds

  • Loading branch information...
1 parent ec0b14b commit d06f81b2f0e36f10f7b9f8f89824cbeca0648292 @bradediger bradediger committed Mar 27, 2012
Showing with 12 additions and 0 deletions.
  1. +4 −0 lib/prawn/images.rb
  2. +8 −0 spec/images_spec.rb
View
4 lib/prawn/images.rb
@@ -77,6 +77,10 @@ def image(file, options={})
# the given image. Return a pair: [pdf_obj, info].
#
def build_image_object(file)
+ # Rewind if the object we're passed is an IO, so that multiple embeds of
+ # the same IO object will work
+ file.rewind if file.respond_to?(:rewind)
+
if file.respond_to?(:read)
image_content = file.read
else
View
8 spec/images_spec.rb
@@ -38,6 +38,14 @@
info.height.should == 453
end
+ it "rewinds IO objects to be able to embed them multiply" do
+ file = File.open(@filename, "rb")
+
+ @pdf.image(file)
+ info = @pdf.image(file)
+ info.height.should == 453
+ end
+
it "should accept Pathname objects" do
info = @pdf.image(Pathname.new(@filename))
info.height.should == 453

0 comments on commit d06f81b

Please sign in to comment.