Page 1 of 1

resolution on png files

Posted: 2011-03-09T10:13:08-07:00
by jburkhart68
When I convert a 72 dpi tiff to png the dpi changes to 71.984. I can convert the same image to gif and the dpi stays at 72. Any idea why this is happening?

Thanks for the help,
Jeff

Re: resolution on png files

Posted: 2011-03-09T13:30:03-07:00
by Drarakel
Hi,

If you save as PNG, the density/resolution will be written into the "pHYs chunk" - but the unit there can only be pixels per meter or undefined, so ImageMagick has to convert the dpi values (see also here). That means, the 72dpi can only be written as 28.34 PixelsPerCentimeter (71.9836 PixelsPerInch) or 28.35 PPC (72.009 PPI). But that still should be precise enough.
You could also use an additional EXIF profile - then, the dpi value would remain as PixelsPerInch. But ImageMagick only creates/updates that profile if there's already such a profile in the input file. (And with TIFF files, it would be even more complicated, as an EXIF profile is not treated as EXIF profile there.) And the natural place for the density in PNG is the aforementioned pHYs chunk.

Re: resolution on png files

Posted: 2011-03-09T14:26:03-07:00
by glennrp
In ImageMagick-6.6.8-2 ou can use the "-define PNG:exclude-chunk=pHYs" option.
Then the PNG encoder will fall back on writing a tEXt:density chunk in dots/inch units.
This might work in other recent versions but I don't know for sure.

Some applications including IM will recognize that. Or you can just round off the result
returned from the pHYs chunk to the nearest integral number. For all practical purposes
it's the same.

Re: resolution on png files

Posted: 2011-03-09T16:32:30-07:00
by jburkhart68
That is very interesting and explains a lot! Thank you very much for your help!

Jeff

Re: resolution on png files

Posted: 2011-03-10T01:34:23-07:00
by Drarakel
glennrp wrote:In ImageMagick-6.6.8-2 ou can use the "-define PNG:exclude-chunk=pHYs" option.
Then the PNG encoder will fall back on writing a tEXt:density chunk in dots/inch units.
Does this really work in IM v6.6.8-2? I don't find a successful command for that - e.g.:

Code: Select all

convert rose: -define png:exclude-chunk=pHYs -set units PixelsPerInch -set density 123 rose.png
This also seems to exclude the tEXt chunks..?

Re: resolution on png files

Posted: 2011-03-11T12:12:56-07:00
by glennrp
Yes it was also removing other text chunks by mistake. That's fixed in
IM-6.6.8-4, SVN r3845. This is also writing the tEXt:density chunk but
as you noted earlier, there is no "units" information stored in the PNG
file to go with it.