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
resolution on png files
-
- Posts: 13
- Joined: 2011-03-08T17:34:27-07:00
- Authentication code: 8675308
Re: resolution on png files
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.
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
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.
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.
-
- Posts: 13
- Joined: 2011-03-08T17:34:27-07:00
- Authentication code: 8675308
Re: resolution on png files
That is very interesting and explains a lot! Thank you very much for your help!
Jeff
Jeff
Re: resolution on png files
Does this really work in IM v6.6.8-2? I don't find a successful command for that - e.g.: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.
Code: Select all
convert rose: -define png:exclude-chunk=pHYs -set units PixelsPerInch -set density 123 rose.png
Re: resolution on png files
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.
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.