lib/prawn/images.rb in prawn-0.2.0 vs lib/prawn/images.rb in prawn-0.2.1

- old
+ new

@@ -34,15 +34,19 @@ # # If only one of :width / :height are provided, the image will be scaled # proportionally. When both are provided, the image will be stretched to # fit the dimensions without maintaining the aspect ratio. # - def image(filename, options={}) + def image(file, options={}) Prawn.verify_options [:at,:position, :height, :width, :scale], options - raise ArgumentError, "#{filename} not found" unless File.file?(filename) - image_content = File.read_binary(filename) + if file.kind_of?(IO) + image_content = file.read + else + raise ArgumentError, "#{file} not found" unless File.file?(file) + image_content = File.read_binary(file) + end image_sha1 = Digest::SHA1.hexdigest(image_content) # register the fact that the current page uses images proc_set :ImageC @@ -81,9 +85,11 @@ page_xobjects.merge!( label => image_obj ) # add the image to the current page instruct = "\nq\n%.3f 0 0 %.3f %.3f %.3f cm\n/%s Do\nQ" add_content instruct % [ w, h, x, y - h, label ] + + return info end private def image_position(w,h,options)