resolution on png files

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
jburkhart68
Posts: 13
Joined: 2011-03-08T17:34:27-07:00
Authentication code: 8675308

resolution on png files

Post 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
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: resolution on png files

Post 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.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: resolution on png files

Post 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.
jburkhart68
Posts: 13
Joined: 2011-03-08T17:34:27-07:00
Authentication code: 8675308

Re: resolution on png files

Post by jburkhart68 »

That is very interesting and explains a lot! Thank you very much for your help!

Jeff
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: resolution on png files

Post 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..?
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: resolution on png files

Post 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.
Post Reply