possible bug PNG24: keeping alpha channel

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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

possible bug PNG24: keeping alpha channel

Post by fmw42 »

IM 6.9.8.10 Q16 Mac OSX

If I create a white circle on a black background and put it into the alpha channel of an opaque image and save to PNG24:, it properly removes the alpha channel

Code: Select all

convert netscape: \
\( -size 144x144 xc:black -fill white -draw "circle 72,72 72,144" \) \
-gravity center -alpha off -compose copy_opacity -composite PNG24:result1.png

Code: Select all

http://www.fmwconcepts.com/misc_tests/png24_bug/result1.png

But if I add -background black -alpha background before saving as PNG24:, it does not remove the alpha channel

Code: Select all

convert netscape: \
\( -size 144x144 xc:black -fill white -draw "circle 72,72 72,144" \) \
-gravity center -alpha off -compose copy_opacity -composite -background black -alpha background PNG24:result2.png

Code: Select all

http://www.fmwconcepts.com/misc_tests/png24_bug/result2.png
Is this a bug?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: possible bug PNG24: keeping alpha channel

Post by snibgo »

"-alpha background" shouldn't remove alpha. It should:
Set any fully-transparent pixel to the background color, while leaving it fully-transparent.
I'm not sure what RGB24: should do when there is alpha. It would seem best to explicitly "-alpha off" if that's what you want.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug PNG24: keeping alpha channel

Post by fmw42 »

I understand. But it seemed strange to me that both files have an alpha channel. The first one with PNG24: turns it off. But the second one with the extra commands does not turn it off.

I would have left PNG24: off, but someone on the GIT web site asked about a similar command and I was surprised that it left the alpha channel on when explicitly adding PNG24:

see https://github.com/ImageMagick/ImageMagick/issues/511
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: possible bug PNG24: keeping alpha channel

Post by glennrp »

Your png32 results have alpha channels with some semitransparent pixels (alpha neither 0 nor 1). I guess "convert" is having difficulty transforming that into PNG24 in which all transparent pixels need to be fully transparent and all of them have to be the same color. Forcing them all to have the same underlying color helps.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug PNG24: keeping alpha channel

Post by fmw42 »

Glenn, sorry, I am confused. Here I only specify PNG24: and both images have the same alpha channel. The only difference is that one has image texture under the alpha and the other has black under the alpha. So why does one leave the alpha channel and the other remove it?
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: possible bug PNG24: keeping alpha channel

Post by glennrp »

fmw42 wrote: 2017-06-13T18:30:40-07:00 Glenn, sorry, I am confused. Here I only specify PNG24: and both images have the same alpha channel. The only difference is that one has image texture under the alpha and the other has black under the alpha. So why does one leave the alpha channel and the other remove it?
I have answered this in the related GIT issue. The source image has transparent areas with different underlying colors. But a PNG24 RGB image uses the PNG tRNS chunk to identify a particular color that is transparent; all pixels with that RGB value are transparent and all others are opaque. So, when you try to convert an image with different-colored transparent pixels to PNG24, it fails. That's not a bug; it's a feature of the PNG format. Use PNG32 or indexed PNG with transparency instead of PNG24 for such images.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug PNG24: keeping alpha channel

Post by fmw42 »

Thanks, Glenn for the explanation. I had thought that PNG24 did not support transparency, only PNG32 and PNG8.

I now see that on Anthony's page at http://www.imagemagick.org/Usage/formats/#png_formats it says:

"PNG24: 8 bit RGB channels without an alpha channel. Special case can include boolean transparency (see below)"
Post Reply