PHP。 Imagecolorallocate 返回 false

发布于 2024-11-18 15:10:52 字数 347 浏览 3 评论 0原文

我使用一些代码:

$colors = array ();
$colors['test'] = imagecolorallocate($img, 0 ,1 ,2);
....

它可以工作,直到我将图片更改为其他
之后imagecolorallocateimagecolorallocatealpha返回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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不美如何 2024-11-25 15:10:52

对该函数的文档进行评论:

如果你甚至处于这样的情况
没有分配你想要的颜色
可能是因为你的图像颜色
分配表。 GIF 和 8 位 PNG
图像很容易受到此影响。

如果您使用 GIF 和 PNG 尝试
从桌子上掉落一种颜色,
应该让你分配另一个。

如果源图像位于索引图像(8 位或更少)中,请确保有空间容纳其他颜色。例如,8 位图像可能不会使用调色板中的所有 256 种颜色,在这种情况下该函数应该成功,否则就不会。

编辑

我查看了您的图像,它实际上是一个使用所有 256 种颜色的 8 位 PNG 图像。尝试将其转换为真彩色图像(通过 Photoshop 或将图像复制到通过 imagecreatetruecolor() 创建的 GD 图像中);完成所有编辑,然后另存为 GIF。

Comment on the documentation of this function:

If you even in a situation where it's
not allocating the color you want it
could be because of your images color
allocation table. GIF and 8-bit PNG
images are very susceptible to this.

If your using an GIF and PNG try
dropping a color from the table,
should let you allocate another.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文