ImageTrueColorToPalette失去颜色 [英] ImageTrueColorToPalette losing colors
问题描述
我有一个PHP脚本,如果图像中不同颜色的数量小于或等于256,则将真彩色图像转换为调色板图像。
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.
在我的测试用例,我有一个包含79种颜色的图像。在没有抖动并且$ ncolors参数设置为79的情况下运行ImageTrueColorToPalette之后,我有一个只有15种颜色的图像。我将它转换为调色板后,甚至尝试在其上运行ImageColorMatch,我最终只有15种颜色。
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.
在PHP中使用GD,我怎样才能转换我的真实彩色图像到调色板图像而不会丢失所有这些颜色?
Using GD in PHP, how can I convert my true color image to a palette image without losing all of those colors?
推荐答案
看来我可以将真彩色图像转换为调色板使用 ImageCreate
创建调色板图像,然后将真彩色图像复制到该图像。这比 ImageTrueColorToPalette
产生更好的结果。
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
.
为什么 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);
这篇关于ImageTrueColorToPalette失去颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!