Menu

#261 PNG Pixel Density Not Preserved Converting to PDF

v1.0_(example)
closed-fixed
None
5
2014-02-06
2014-02-06
Dave
No

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

  1. Make a 300 dpi 8.5" x 11" image (this is a resolution of 2550x3300), and save it as input.png.
  2. Run convert command:
    gm convert input.png output.pdf
  3. Open output.pdf in Adobe Reader (or other PDF viewer) to check size.

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

Related

Bugs: #253

Discussion

  • Bob Friesenhahn

    Bob Friesenhahn - 2014-02-06
    • assigned_to: Bob Friesenhahn
     
  • Bob Friesenhahn

    Bob Friesenhahn - 2014-02-06

    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.

     
  • Glenn Randers-Pehrson

    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

    gm convert -size 2550x3300 -density 300x300 \
               -units PixelsPerInch xc:blue blue.png
    

    That creates a good PNG with resolution 11811x11811 pixels/meter (300 dpi)

    gm convert blue.png blue.pdf
    gm identify blue.pdf
    

    The resulting PDF 2550x3300 and has no resolution or density information.

     

    Last edit: Glenn Randers-Pehrson 2014-02-06
    • Bob Friesenhahn

      Bob Friesenhahn - 2014-02-06

      On Thu, 6 Feb 2014, Glenn Randers-Pehrson wrote:

      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.

      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.

       
  • Bob Friesenhahn

    Bob Friesenhahn - 2014-02-06
    • status: open --> closed-fixed
     
  • Bob Friesenhahn

    Bob Friesenhahn - 2014-02-06

    Fixed by Mercurial changeset 14025:403d2c2b081e

     

Log in to post a comment.

MongoDB Logo MongoDB