【发布时间】:2013-08-21 06:14:30
【问题描述】:
我已经编写了一些代码来调整图像的大小(遵循 PHP 手册),但我无法让图像显示。我知道图像数据存在,因为当我回显 $thumb 时可以看到它,但我似乎无法显示实际图像。
这是我使用的代码:
$row = mysql_fetch_array($result);
$image = $row["image"];
echo $image;
echo $row["name"];
list($width, $height) = getimagesize($image);
$newwidth = $width * 0.1;
$newheight = $height * 0.1;
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($image);
imagecopyresized($thumb, $source, 0,0,0,0, $newwidth, $newheight, $width, $height);
header('Content-Length: '.strlen($thumb), true);
header("Content-type: image/jpeg");
echo imagejpeg($thumb);
感谢您的帮助
【问题讨论】:
-
删除
echo。imagejpeg($thumb)就足够了(如果 $thumb 是适当的图像资源) -
查看您实际发送的信息,方法是保存到文件中或使用网络嗅探器。当某些东西不起作用时,请始终准确查看实际产生的内容,不要停留在元级别(“不起作用”)。发送的内容真的是 jpeg 吗?不。如果你看一下内容,你就会看到。
-
尝试消除回声,但我得到的只是数据而不是实际图像,但无论如何谢谢。
-
我不确定你所说的使用“网络嗅探器”是什么意思 我对 PHP 还很陌生,所以我没有那么多经验。原始文件是一个 jpeg,我假设代码(取自 PHP 手册)创建另一个 jpeg。
标签: php