kornelski / pngquant

Lossy PNG compressor — pngquant command based on libimagequant library
https://pngquant.org
Other
5.25k stars 486 forks source link

Alpha Channel Removal Issue When All Values Are 255 #419

Open linkillhz opened 4 months ago

linkillhz commented 4 months ago

Hello,

I've encountered an issue with pngquant where the alpha channel is removed when all alpha values in the original image are 255 (completely opaque). After optimization, the output file no longer contains the alpha channel.

Issue Description

When I run pngquant on an image where every pixel's alpha value is 255, the resulting file seems to have the alpha channel completely removed. This behavior is unexpected because I would prefer to retain the alpha channel even if it is fully opaque.

Steps to Reproduce

Prepare a PNG image where every pixel's alpha value is 255. pngquant --force --output optimized.png original.png Check the resulting optimized.png file.

Actual Behavior

The alpha channel is removed, and the resulting image does not have an alpha channel.

Question

Is this the intended behavior when all alpha values are 255? If so, is there a way to force pngquant to retain the alpha channel in the output file even when all alpha values are completely opaque?

Thank you for your assistance.

kornelski commented 4 months ago

In the PNG8 format there is no such thing as an alpha channel.

It's a palette based image. If all pixels have alpha 255, then there's no reason to create palette with other alpha values, and they wouldn't be used anyway.