在 PHP 脚本中选择 gif 的颜色数

Choosing the number of colors of a gif in a PHP Script

我正在创建一个将图像转换为 GIF 的函数。

我在 PHP 网站上没有找到任何关于可以限制输出 gif 颜色数量的功能的文档,你能帮我吗?

这是我正在使用的一些代码:

$image = imagecreatefrompng($this->_backgroundImage);
header('Content-Type: image/gif');

return imagegif($image);

好的,我找到了我要找的功能:imagetruecolortopalette

imagetruecolortopalette($image, false, 2);