使用imagepng输出php创建的图片出现错误

骑着母猪砍大象1 2016-12-26 02:19:08
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

</head>
<?php

$img1 = imageCreateTrueColor(100, 50);


$color1 = imageColorAllocate($img1, rand(0,255), rand(0,255), rand(0,255));
imagestring($img1, 5, 10, 3, "1234", $color1);

header("content-type:image/jpeg");
imagejpeg($img1);
imagedestroy($img1);

?>

</body>
</html>
...全文
358 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
一起混吧 2016-12-26
  • 打赏
  • 举报
回复
meta 那句删除 最后的?> 也是可以删除的
  • 打赏
  • 举报
回复
这是修改后的
  • 打赏
  • 举报
回复
一起混吧 2016-12-26
  • 打赏
  • 举报
回复
不行?哪里不行?html 代码不是图片内容,所以应该删去。
  • 打赏
  • 举报
回复
不行,代码方面应该是没问题的,感觉是不是什么其他问题,屏蔽header之后输出就是一大长串错误乱码,都不知道什么问题
一起混吧 2016-12-26
  • 打赏
  • 举报
回复
只留下php代码,其他的html代码删除
<?php

 $img1 = imageCreateTrueColor(100, 50);


 $color1 = imageColorAllocate($img1, rand(0,255), rand(0,255), rand(0,255));
 imagestring($img1, 5, 10, 3, "1234", $color1);

 header("content-type:image/jpeg");
 imagejpeg($img1);
 imagedestroy($img1);
  • 打赏
  • 举报
回复
图片一直显示不出来

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧