Re: PNG with indexed colors and tranparency

Przemysław Sobala <[email protected]> Fri, 28 Jun 2019 15:32:46 +0200
Newsgroups gmane.comp.video.graphicsmagick.help
Message-ID <[email protected]>
W dniu 28.06.2019 o 15:08, Bob Friesenhahn pisze:
> On Fri, 28 Jun 2019, Przemysław Sobala wrote:
>>
>> And it turns out that GraphicsMagick can't do that because of Cannot 
>> write image as indexed PNG, writing RGBA message.
>> Look for transparent colormap entry reveals num_alpha = 47and in 
>> coders/png.c there's an if
>>
>>                       if (num_alpha == 1)
>>
>>                       else
>>                       {
>> ping_colortype=PNG_COLOR_TYPE_RGB_ALPHA;
>>
>> I tried some other PNG images with transparency and they all have 
>> num_alpha>1.
>>
>> Does that mean that GraphicsMagick can't handle creating palette PNG 
>> images with transparency? How can I obviate that? Is reducing number 
>> of transparent colors in palette to 1 the best solution?
>
> I am not sure about PNG but it is not unusual (e.g. GIF) that palette 
> formats only support one transparent color.  I also know that there 
> are some weaknesses in the implementation that Glenn did not address.
>
> In GraphicsMagick, colormap entries do have an opacity property 
> (inverse of transparency/alpha channel) but opacity is not considered 
> for color reduction except that one color can be 'transparent' if the 
> specified colorspace (-colorspace) is Transparent.
>
> It may be necessary to assure that there is only one transparent color 
> when attempting to write an indexed PNG with transparency.
>
> We could really use a PNG expert to join the development team and work 
> on improving the PNG writer.
>
> Bob

I got around this limitation via "-operator Opacity Depth 1" but I still 
don't know is it the best way to do it. Also, the output image is a 
little bit distorted due to that opacity dynamic range reduction.

My final command line is now:
gm convert -debug coders europe.png -operator Opacity Depth 1 -colors 
255 test.png

The reason I fight for that indexed colors is the size of my output 
image, 3 x smaller that with RGBA.

--
Best regards
Przemysław Sobala

_______________________________________________
Graphicsmagick-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/graphicsmagick-help