Why does Prawn automatically resize my image?

When I try to insert an image (PNG at 72dpi) using Prawn, like this:

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

The shrimp inserts the image, but scales it by about 30%, which makes it blurry (and large). I have nothing else in the file, and PDF initialization is pretty 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 the documentation, the shrimp should insert the image into the document without any changes. Why does the image resize?


Note: I noticed that the bounding rectangles are also larger than they should be (in the same ratio as my image).

+7
source share
1 answer

you can try to convey the width and height of the image that is actually displayed, if that helps

Shrimp :: Images

Public Data Methods image (file, options = {}) Click to switch source

Add the image to the file name on the current page. Currently, only JPG and PNG files are supported.

NOTE. Shrimp is very slow when rendering PNG with alpha channels. workaround for those who do not want to install RMagick:

github.com/amberbit/prawn-fast-png

Arguments:

path to file or object that responds to #

Options:

: at array [x, y] with the location of the upper left corner of the image.

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

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

: height image height [actual image height]

: width image width [actual image width]

: Scale proportionally scales image sizes

: Fit scales the image proportionally to the size inside [width, height]

 Prawn::Document.generate("image2.pdf", :page_layout => :landscape) do 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 only one of: width /: height is provided, the image will scale proportionally. When both are provided, the image will be stretched to fit without maintaining aspect ratio.

If: at is provided, the image will be placed on the current page, but the text position will not be changed.

If, instead of an explicit file name, an object with a read method is transferred as a file, you can insert images from I / O objects and things that act like them (including Tempfiles and open-uri objects).

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

This method returns an image information object that can be used to check the size of the image object, if necessary. (See Also: Shrimp :: Images :: PNG, Shrimp :: Images :: JPG)

+5
source

All Articles