我已经编写了一些代码来调整图像大小(遵循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);
感谢您的帮助
答案 0 :(得分:2)
\t
$thumb
echo $image;
和echo $row["name"];
。 index.php:
$row = mysql_fetch_array($result);
$image = $row["image"];
echo $image;
echo $row["name"];
echo '<img src="image.php">';
image.php:
$row = mysql_fetch_array($result);
$image = $row["image"];
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);
$h = str_replace('\t','',$thumb);
header('Content-Length: '.strlen($h), true);
header("Content-type: image/jpeg");
imagejpeg($thumb);