I have a PHP script that converts true color images to palette images if the number of different colors in the image is less than or equal to 256.
In my test case, I have an image that contains 79 colors. After running ImageTrueColorToPalette on it without dither and the $ncolors parameter set to 79, I have an image that only has 15 colors in it. I have even tried running ImageColorMatch on it after converting it to palette, and I still end up with only 15 colors.
Using GD in PHP, how can I convert my true color image to a palette image without losing all of those colors?
It appears I can convert the true color image to a palette image by creating a palette image using
ImageCreateand then copying the true color image to that one. This produces much better results thanImageTrueColorToPalette.Why
ImageTrueColorToPalettegives me a crappy looking image, I’m not really sure, but this seems like an adequate workaround.