php-vips icon indicating copy to clipboard operation
php-vips copied to clipboard

Color Quantization

Open olivervogel opened this issue 11 months ago • 4 comments

Is it possible in any way to reduce the distinct colors in an image with the result being visually similar as possible to the original?

I have found out that I can achieve this by setting the palette and bitdepth parameters when encoding to PNG format.

The question I am asking myself is whether this is also possible outside or before the encoding process and without committing to a certain image format. And if this is the case, is it also possible to reduce to any number of colors instead of fixed bit depths?

Thanks in advance.

olivervogel avatar Jan 07 '25 15:01 olivervogel

The GIF saver has this functionality too, though it's also limited to a choice of 2, 4, 8, 16, 32, 64, 128, 256 colours.

There's a PR with some code to expose this as a general operation, but it hasn't been merged because of some upstream issues.

jcupitt avatar Jan 07 '25 17:01 jcupitt

Ok thanks, looking forward to it being possible in the future.

olivervogel avatar Jan 07 '25 18:01 olivervogel

The GIF saver has this functionality too, though it's also limited to a choice of 2, 4, 8, 16, 32, 64, 128, 256 colours.

There's a PR with some code to expose this as a general operation, but it hasn't been merged because of some upstream issues.

Did that PR ever get merged?

jardayn avatar Oct 20 '25 19:10 jardayn

It's this PR:

https://github.com/libvips/libvips/pull/3122

It needs a small upstream change, unfortunately.

jcupitt avatar Oct 21 '25 08:10 jcupitt