Page 1 of 1
Transparent changes density
Posted: 2016-02-09T14:29:56-07:00
by MysterB
I am using Convert from the command line to make changes to a PNG file.
Whenever I add the "-alpha transparent" parameter it changes the density from the original 300 dpi to 120 dpi.
How do I keep the density at 300 dpi? ("-density 300" does not seem to work)
Thanks in advance
Re: Transparent changes density
Posted: 2016-02-09T14:41:39-07:00
by snibgo
It works fine for me, IM v6.9.2-5 on Windows 8.1.
Please state the version of IM you are using, and the platform. Exactly what is your command? Does this happen with all input PNGs? Only with PNG? Please provide a sample input.
Re: Transparent changes density
Posted: 2016-02-10T06:59:32-07:00
by MysterB
I have two versions of the software and they both do the same thing. I am using it on Windows 7 and on Windows Server 2012. I am just using this on PNG files. (PNG to PNG). What I am doing is using another third party product to convert eps and ps files to PNG files. Then I am using this software to create a transparent version of the PNG (where possible). This procedure was recommended by the third party supplier. The file _out1.png is an output of the ps to png conversion. This procedure works good except for the change in dpi from 300 down to 120 in the second part (the step below).
With version 6.3.4 the command I am using is:
img2img.exe _out1.png -trim -transparent white circle.png
The original _out1.png (300dpi) gets converted to circle.png (at 120dpi)
With version 6.9.3 the command I am using is:
convert _out1.png -trim transparent white circle.png
or you can use:
convert _out1.png -trim -alpha transparent circle.png
both seem to do the same thing as above (convert and lower the dpi from 300 to 120)
Note that "trim" and "transparent" both seem to have the same effect of reducing the dpi
Note also that adding "-r 300" or "-density 300" does not fix the issue
Is there a way to upload a small sample file here?
Re: Transparent changes density
Posted: 2016-02-10T07:52:42-07:00
by glennrp
How is the density stored in the original PNG? If you have pngcheck, run "pngcheck -v _out1.png". The density should be in the pHYs chunk but it might instead be in a tEXt or iTXt chunk.
Re: Transparent changes density
Posted: 2016-02-10T08:02:39-07:00
by MysterB
Interesting tool pngcheck. It doesn't seem to like the NULL characters.
File: _out1.png (44988 bytes)
chunk IHDR at offset 0x0000c, length 13
2550 x 3300 image, 24-bit RGB, non-interlaced
chunk pHYs at offset 0x00025, length 9: 11811x11811 pixels/meter (300 dpi)
chunk tEXt at offset 0x0003a, length 29: text contains NULL character(s)
ERRORS DETECTED in _out1.png
Re: Transparent changes density
Posted: 2016-02-10T09:24:16-07:00
by snibgo
You can upload image files to somewhere like dropbox.com and paste the URLs here.
Code: Select all
img2img.exe _out1.png -trim -transparent white circle.png
This looks like a variant of ImageMagick. What does...
... say?
Re: Transparent changes density
Posted: 2016-02-10T09:32:33-07:00
by MysterB
img2img -version
Version: ImageMagick 6.3.4 05/11/07 Q16
http://www.imagemagick.org
Copyright: Copyright (C) 1999-2007 ImageMagick Studio LLC
Files are at:
https://www.dropbox.com/sh/b346uuju803d ... Ntm1a?dl=0
Re: Transparent changes density
Posted: 2016-02-10T09:39:18-07:00
by MysterB
One interesting note: pngcheck says that my output file (circle.png) has a density of 300dpi, but graphic tool (paint) shows the file to be 120 dpi. I need to do some testing to see which is reporting the truth.
So it looks like the meta data on the file is being read differently by different code. In Microsoft (MS Paint) and the MS Library to read the meta data from code (used in my application), it is reporting the dpi at 120. Other programs (pngcheck, photoshop) show the meta data as saying it is 300 dpi. How do I fix it so that Microsoft code and products see the dpi correctly at 300?
Re: Transparent changes density
Posted: 2016-02-10T13:22:55-07:00
by MysterB
Online it says that you should be able to change the dpi using ImageMagick and the following command:
convert -density 300 -units pixelsperinch circle.png circle.png
but it does not update it (from the Microsoft point of view)
Re: Transparent changes density
Posted: 2016-02-11T11:16:42-07:00
by glennrp
We can't help you much with the bug in MS Paint. 300dpi (or 299.9994 dpi) is the correct interpretation of the pHYs metadata in the PNG file.