ImageTrueColorToPalette losing colors

半腔热情 提交于 2019-12-12 23:07:52

问题


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?


回答1:


It appears I can convert the true color image to a palette image by creating a palette image using ImageCreate and then copying the true color image to that one. This produces much better results than ImageTrueColorToPalette.

Why ImageTrueColorToPalette gives me a crappy looking image, I'm not really sure, but this seems like an adequate workaround.

$palette = ImageCreate($width, $height);
ImageCopy($palette, $truecolor, 0, 0, 0, 0, $width, $height);


来源:https://stackoverflow.com/questions/5187480/imagetruecolortopalette-losing-colors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!