Transparent changes density

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
MysterB
Posts: 6
Joined: 2016-02-09T14:25:02-07:00
Authentication code: 1151

Transparent changes density

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Transparent changes density

Post 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.
snibgo's IM pages: im.snibgo.com
MysterB
Posts: 6
Joined: 2016-02-09T14:25:02-07:00
Authentication code: 1151

Re: Transparent changes density

Post 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?
Last edited by MysterB on 2016-02-10T07:53:01-07:00, edited 1 time in total.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Transparent changes density

Post 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.
MysterB
Posts: 6
Joined: 2016-02-09T14:25:02-07:00
Authentication code: 1151

Re: Transparent changes density

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Transparent changes density

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

Code: Select all

img2img -version
... say?
snibgo's IM pages: im.snibgo.com
MysterB
Posts: 6
Joined: 2016-02-09T14:25:02-07:00
Authentication code: 1151

Re: Transparent changes density

Post 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
MysterB
Posts: 6
Joined: 2016-02-09T14:25:02-07:00
Authentication code: 1151

Re: Transparent changes density

Post 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?
MysterB
Posts: 6
Joined: 2016-02-09T14:25:02-07:00
Authentication code: 1151

Re: Transparent changes density

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

Re: Transparent changes density

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