Page 1 of 1
possible bug PNG24: keeping alpha channel
Posted: 2017-06-13T15:22:27-07:00
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?
Re: possible bug PNG24: keeping alpha channel
Posted: 2017-06-13T15:32:43-07:00
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.
Re: possible bug PNG24: keeping alpha channel
Posted: 2017-06-13T15:34:08-07:00
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
Re: possible bug PNG24: keeping alpha channel
Posted: 2017-06-13T16:32:51-07:00
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.
Re: possible bug PNG24: keeping alpha channel
Posted: 2017-06-13T18:30:40-07:00
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?
Re: possible bug PNG24: keeping alpha channel
Posted: 2017-06-14T11:16:42-07:00
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.
Re: possible bug PNG24: keeping alpha channel
Posted: 2017-06-14T11:23:07-07:00
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)"