需要 PHP GD imagesetpixel() 的帮助
$imageurl = "kaptka.gif";
$im = imagecreatefromgif($imageurl);
$b = imagecolorallocate($im, 0, 0, 0);
imagesetpixel($im, 5, 5, $b);
header('Content-Type: image/gif');
imagegif($im, "asd.gif");
kaptka.gif 是普通的 gif 图像。我想在图像上的任何位置绘制一些像素。 Asd.gif 看起来很正常,但是当我打开文件时,它应该像 asd.gif 一样显示给我,但它只显示“IMAGE”文本。
$imageurl = "kaptka.gif";
$im = imagecreatefromgif($imageurl);
$b = imagecolorallocate($im, 0, 0, 0);
imagesetpixel($im, 5, 5, $b);
header('Content-Type: image/gif');
imagegif($im, "asd.gif");
kaptka.gif is normal gif image. I want to draw some pixels anywhere on the image. Asd.gif looks normal, but when i open the file it should show me both like asd.gif, but it shows just "IMAGE" text.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用文件名调用函数
imagegif()
。这会将映像写入光盘。要显示内容,只需在不带文件名的情况下调用它:这会将内容传递到输出流,这意味着它将被发送到客户端的浏览器。执行这两项操作的一种方法是调用它两次,一次用于保存文件,一次用于显示文件。保存文件时,您可以将结果赋给变量
$foo=imagegif($im, 'bar.gif')
,然后检查结果以查看保存是否成功。 FALSE 表示失败。您说保存到服务器的图像没问题,所以您在浏览器中收到“IMAGE text”的原因可能是因为您正在发送 PNG 标头,但没有数据(因为您调用
imagefig( )
)。You are calling the function
imagegif()
with a filename. This will write the image to disc. To display the contents, simply call it without the filename: this will pass the contents to the output stream, which means it will be sent to the client's browser. One way to do both is to call it twice, once to save the file, and once to display it.When saving the file, you can assign the result to a variable
$foo=imagegif($im, 'bar.gif')
and then check the result to see if the save was successful. A FALSE means it failed.You say the image saved to the server is OK, so the reason you are getting an "IMAGE text" in your browser is probably because you are sending a PNG header, but no data (because of the way you called
imagefig()
).