Conversion of PNG with/without physical info to A4 PDF
Posted: 2013-06-10T14:33:24-07:00
I have some scans (300 DPI) which I'd like to convert to A4 PDFs, however imagemagick seems to behave in an unexpected way if the PNG metadata contains physical info (pHYs chunk).
To reproduce, I created a 2479x3508 image at 300 DPI using Gimp. Next, I exported it twice, with and without Save resolution checked in the PNG export dialog.
PNG can only store units in pixels per meter - displayed by imagemagick as PixelsPerCentimeter - but it's approximately 300 DPI.
Now, converting both files to PDF using different imagemagick params:
With -page:
First image: converts to a page size of 595 x 842 (exactly as specified by imagemagick for -page A4).
Second image: results in an unexpected page size (even if PNG PixelsPerCentimeter -> DPI conversion causes some loss, I'd expect it to be at least an A4 approximate)
Without -page:
First image: as expected (no physical metadata present)
Second image: approximate A4 size, though slightly off (conversion?)
Am I incorrectly using Imagemagick? I would expect -page A4 to produce a 595x842 PDF regardless of pHYs presence. Is this a bug?
Some additional (failed) attempts at explicitly specifying source image physical dimensions:
Version info:
To reproduce, I created a 2479x3508 image at 300 DPI using Gimp. Next, I exported it twice, with and without Save resolution checked in the PNG export dialog.
Code: Select all
$ identify -verbose black_* | grep -A6 Image:
Image: black_nophys.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 2479x3508+0+0
Units: Undefined
Type: Bilevel
Endianess: Undefined
--
Image: black_phys.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 2479x3508+0+0
Resolution: 118.11x118.11
Print size: 20.9889x29.7011
Units: PixelsPerCentimeter
Now, converting both files to PDF using different imagemagick params:
With -page:
Code: Select all
$ convert black_nophys.png -page A4 test.pdf && pdfinfo test.pdf | grep 'Page size'
Page size: 595 x 842 pts (A4)
$ convert black_phys.png -page A4 test.pdf && pdfinfo test.pdf | grep 'Page size'
Page size: 142.8 x 202.08 pts
Second image: results in an unexpected page size (even if PNG PixelsPerCentimeter -> DPI conversion causes some loss, I'd expect it to be at least an A4 approximate)
Without -page:
Code: Select all
$ convert black_nophys.png test.pdf && pdfinfo test.pdf | grep 'Page size'
Page size: 2479 x 3508 pts
$ convert black_phys.png test.pdf && pdfinfo test.pdf | grep 'Page size'
Page size: 594.96 x 841.92 pts (A4)
Second image: approximate A4 size, though slightly off (conversion?)
Am I incorrectly using Imagemagick? I would expect -page A4 to produce a 595x842 PDF regardless of pHYs presence. Is this a bug?
Some additional (failed) attempts at explicitly specifying source image physical dimensions:
Code: Select all
$ convert -units PixelsPerInch -density 300 black_phys.png -page A4 test.pdf && pdfinfo test.pdf | grep 'Page size'
Page size: 142.8 x 202.08 pts
$ convert -units PixelsPerInch -density 300 black_nophys.png -page A4 test.pdf && pdfinfo test.pdf | grep 'Page size'
Page size: 142.8 x 202.08 pts
$ convert black_nophys.png -set units PixelsPerInch -density 300 -page A4 test.pdf && pdfinfo test.pdf | grep 'Page size'
Page size: 142.8 x 202.08 pts
$ convert black_phys.png -set units PixelsPerInch -density 300 -page A4 test.pdf && pdfinfo test.pdf | grep 'Page size'
Page size: 142.8 x 202.08 pts
Code: Select all
Version: ImageMagick 6.8.5-10 2013-06-07 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib fontconfig freetype gslib jng jp2 jpeg lcms lqr lzma openexr pango png ps rsvg tiff wmf x xml zlib