PNG Pixel Density Not Preserved Converting to PDF
Swiss army knife of image processing
Brought to you by:
bfriesen
Description
The pixel density stored in PNG files is not preserved when converting to PDF format. This may be related to [#253]. Not sure if it applies to other image formats as well.
Steps
Expected Result
Page Size reported by PDF viewer as 8.50 x 11.00 in.
Actual Result
Page Size reported by PDF viewer as 35.42 x 45.83 in.
This means that the output density is being set to 72 dpi even though the source is 300 dpi.
Notes
Using the -density option to force 300 dpi produces the expected 300 dpi 8.5" x 11" output PDF.
e.g.
gm convert -density 300 input.png output.pdf
I am able to reproduce the problem here. It must be a problem in the PDF writer rather than with PNG. Thanks for the bug report and the hint about working with -density.
If you want the PNG to supply the density, you have to supply both
density and units to the PNG encoder when creating the PNG.
Using a recent gm snapshot, GraphicsMagick 1.4 snapshot-20140102 Q16
That creates a good PNG with resolution 11811x11811 pixels/meter (300 dpi)
The resulting PDF 2550x3300 and has no resolution or density information.
Last edit: Glenn Randers-Pehrson 2014-02-06
On Thu, 6 Feb 2014, Glenn Randers-Pehrson wrote:
Regardless, the PDF coder has an obvious problem in that it is not
using the image resolution at all. Instead it is processing ImageInfo
density (from -density option). Clearly this is due to a
misunderstanding by whomever wrote this bit of code. The fix seems
easy enough but requires care to make sure it is completely correct.
Fixed by Mercurial changeset 14025:403d2c2b081e