当浏览器显示图像时,它将被单独下载并放置在页面上。因此,您不能在一个请求中发送HTML和图片。您需要的是一个html/php页面,该页面有一个标记,其中src设置为另一个只发送图像数据的页面。
如:
(索引php)
<html>
<body>
<image src="pic.php" />
</body>
</html>
现在,在另一个名为(pic.php)的文件中,您将生成图像并将其发送回带有“content-type”标题的响应,而绝对没有其他内容(可能除了其他标题)。
如从
http://www.webdeveloper.com/forum/showpost.php?p=879552&postcount=2
<?php
$number = "";
for ($i = 1; $i <= $lenght; $i++)
{
$number .= rand(0,9)."";
}
$width = 11*$lenght;
$height = 30;
$img = ImageCreate($width, $height);
$background = imagecolorallocate($img,255,255,255);
$color_black = imagecolorallocate($img,0,0,0);
$color_grey = imagecolorallocate($img,169,169,169);
imagerectangle($img,0, 0,$width-1,$height-1,$color_grey);
imagestring($img, 5, $lenght, 7, $number, $color_black);
//////// VERY IMPORTANT
header('Content-Type: image/png');
//////// VERY IMPORTANT
imagepng($img);
imagedestroy($img);
?>