ruby on rails - Why does Prawn resize my image automatically? -


when try insert image (png @ 72dpi) using prawn, this:

image "#{rails.root}/public/images/pdf/logo.png" 

prawn inserts image scales 30% makes blurry (and bigger.) dont have else in file , pdf initialization standard:

super(:page_layout => :portrait,       :left_margin => 0.5.in,       :right_margin => 0.5.in,       :top_margin => 1.in,       :bottom_margin => 0.5.in) 

based on documentation, prawn supposed insert picture document without modifications whatsoever. why image resizing happening?


note: noticed bounding boxes bigger should (by same ratio image).

you can try passing width , height image see if helps

prawn::images

public instance methods image(file, options={}) click toggle source

add image @ filename current page. jpg , png files supported.

note: prawn slow @ rendering pngs alpha channels. workaround don’t mind installing rmagick use:

github.com/amberbit/prawn-fast-png

arguments:

file path file or object responds #

options:

:at array [x,y] location of top left corner of image.

:position 1 of (:left, :center, :right) or x-offset

:vposition 1 of (:top, :center, :center) or y-offset

:height height of image [actual height of image]

:width width of image [actual width of image]

:scale scale dimensions of image proportionally

:fit scale dimensions of image proportionally fit inside [width,height]

prawn::document.generate("image2.pdf", :page_layout => :landscape)          pigs = "#{prawn::basedir}/data/images/pigs.jpg"      image pigs, :at => [50,450], :width => 450                                            dice = "#{prawn::basedir}/data/images/dice.png"     image dice, :at => [50, 450], :scale => 0.75    end    

if 1 of :width / :height provided, image scaled proportionally. when both provided, image stretched fit dimensions without maintaining aspect ratio.

if :at provided, image place in current page text position not changed.

if instead of explicit filename, object read method passed file, can embed images io objects , things act them (including tempfiles , open-uri objects).

  require "open-uri"    prawn::document.generate("remote_images.pdf")      image open("http://prawn.majesticseacreature.com/media/prawn_logo.png")   end 

this method returns image info object can used check dimensions of image object if needed. (see also: prawn::images::png , prawn::images::jpg)


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -