kornelski / pngquant

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

Feature Request: Option to skip image if it already has 256 colors or less. #397

Closed trlkly closed 1 year ago

trlkly commented 1 year ago

I mostly use pngquant to convert images to 8-bit palleted PNG (aka PNG8). Most of the time, it works great. But occasionally the image I started with already had less than 256 colors, and the result is usually that this gets reduced to a much lower number of colors.

I would prefer an option to tell it to skip the image if it has 256 colors or less. You already do check the number of colors as part of the conversion process, so it would be nice to say to skip reducing the colors of images if there are few enough colors. (Perhaps you could even set the number of colors.)

I do currently have a workaround in a batch file that uses ImageMagick to check the number of colors but it would be nice if pngquant could do it natively, since it already checks the number of colors. It would further be nice if it would still convert the image to PNG8, though this is optional since I optimize the PNG.

kornelski commented 1 year ago

I assume you're using it with the --quality option that doesn't allow preserving 100% quality? Because otherwise it should just keep the input colors. Any difference may be from unused colors.

trlkly commented 1 year ago

I copied the settings from a project, and they used 99, not 100. I assumed 99 was the max. You're correct, if I allow 100, it does keep the file.