为什么php imagefill总是黑的?
这让我抓狂。如果您告诉我为什么我在本地 xampp 安装中看到这个红色方块的任何想法,我将非常感激。如果我在远程服务器中运行代码 (http://www.arreglaordenador.com/numberimage2.php< /a>) 我看到的方块是黑色而不是红色。你有什么想法吗?
<?php
$im = imagecreatetruecolor(100, 100);
// sets background to red
$red = imagecolorallocate($im, 255, 0, 0);
imagefill($im, 0, 0, $red);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
谢谢
This is driving me mad. I would really appreciate if you told me any idea about why I see this square in red color just in my local xampp installation. If I run the code in the remote server (http://www.arreglaordenador.com/numberimage2.php) I see the square in black color instead of red. Do you have any ideas?
<?php
$im = imagecreatetruecolor(100, 100);
// sets background to red
$red = imagecolorallocate($im, 255, 0, 0);
imagefill($im, 0, 0, $red);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是因为您使用
imagecreatetruecolor()
函数创建图像,并且您的GD版本有错误。imagecreatetruecolor()
在某些 GD 版本中不会被某些颜色函数覆盖(我不记得是哪个)。你有两个解决方案。或
imagecreate()
函数来创建图像标识符,而不是imagecreatetruecolor()
。It's because you have used
imagecreatetruecolor()
function to create image and your GD version has bugs.imagecreatetruecolor()
won't override by some color function in some GD versions(I don't remember which). You have two solutions.or
imagecreate()
function to create image identifier insteadimagecreatetruecolor()
.您可以先尝试分配不同的颜色吗?
我不明白为什么,但这对我来说看起来像是一个透明度问题(即由于某种原因选择红色作为透明颜色)。
这很可能是由于 GD 版本不同造成的。您能比较一下本地和远程的哪一个吗?
Can you try allocating a different colour first?
I don't exactly see why, but this looks like a transparency issue to me (i.e. red being selected as a transparent colour for some reason).
Most probably, this is due to different GD versions. Can you compare which one you have locally and which one remotely?
根据
imagecreatetruecolor()
文档,您的服务器可能没有安装了正确版本的 GD 映像库。Based on the
imagecreatetruecolor()
documentation, your server probably doesn't have the correct version of the GD image library installed.这绝对是您服务器上的 GD 问题,因为您的代码在我的本地 WAMP 和我的托管帐户上都运行良好。
This is definitely a GD issue on your server because your code works just fine on both my local WAMP and on my hosting account.