PHP。 Imagecolorallocate 返回 false
我使用一些代码:
$colors = array ();
$colors['test'] = imagecolorallocate($img, 0 ,1 ,2);
....
它可以工作,直到我将图片更改为其他
之后imagecolorallocate
和imagecolorallocatealpha
返回false
$img
是正确的图像,即 imagepng
正确打印它
如何使 imagecolorallocate
工作?
I use some code:
$colors = array ();
$colors['test'] = imagecolorallocate($img, 0 ,1 ,2);
....
It works until I change picture to other
After that imagecolorallocate
and imagecolorallocatealpha
return false
$img
is correct image, i.e imagepng
print it correctly
How to make imagecolorallocate
work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对该函数的文档进行评论:
如果源图像位于索引图像(8 位或更少)中,请确保有空间容纳其他颜色。例如,8 位图像可能不会使用调色板中的所有 256 种颜色,在这种情况下该函数应该成功,否则就不会。
编辑
我查看了您的图像,它实际上是一个使用所有 256 种颜色的 8 位 PNG 图像。尝试将其转换为真彩色图像(通过 Photoshop 或将图像复制到通过
imagecreatetruecolor()
创建的 GD 图像中);完成所有编辑,然后另存为 GIF。Comment on the documentation of this function:
If the source image in an indexed image (8-bit or less) then make sure there is room for additional colors. E.g. an 8-bit image might not be using all 256 colors from the palette in that case the function should succeed and it will not otherwise.
Edit
I looked at your image and it is infact an 8-bit PNG image that uses all 256 colors. Try converting it to a true color image (either via photoshop or by copying the image into a GD image created via
imagecreatetruecolor()
); do all the editing, then save as GIF.