【发布时间】:2013-10-29 11:14:37
【问题描述】:
问题:
我找到了这个解释如何使用 imagejpeg() 的简单脚本:
<?php
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
header('Content-Type: image/jpeg');
imagejpeg($im);
imagedestroy($im);
?>
当我将它复制/粘贴到一个空的 php 文件中时,它工作得很好。我显示一个图像。
现在,当我将此代码插入我现有的 php 文件之一时,格式如下:
<!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>Untitled Document</title>
</head>
<body>
***code above***
</body>
</html>
它不返回任何图像。只是几行奇怪的字符。
我认为会发生什么:
我阅读了其他帖子,我认为问题出在我的主标题“Content-Type”上。但我不明白为什么嵌入代码中的“Content-Type:image/jpeg”不能取代主标题中写的任何内容?它应该告诉 imagejpeg() 显示图像,而不是文本...
有人知道怎么解决吗?谢谢。
【问题讨论】:
标签: php