Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit d06f81b2f0e36f10f7b9f8f89824cbeca0648292 1 parent ec0b14b
Brad Ediger bradediger authored
Showing with 12 additions and 0 deletions.
  1. +4 −0 lib/prawn/images.rb
  2. +8 −0 spec/images_spec.rb
4 lib/prawn/images.rb
View
@@ -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
8 spec/images_spec.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.