<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>php--创建图像</title>
</head>
<body>
<?PHP
header('Content-Type:image/png');
$im = imagecreatetruecolor(200,200);
imagepng($im);
?>
</body>
</html>
Hi,使用php输出图片的时候,在header('Content-Type:image/png');函数之前不能有任何的内容输出(像html代码是直接输出的,也不能使用echo等函数哦),否则浏览器无法辨别请求的内容是一张图片,导致图片不显示。解决办法去掉多余的代码:
header('Content-Type:image/png');
$im = imagecreatetruecolor(200,200);
imagepng($im);
?>
温馨提示:答案为网友推荐,仅供参考