我找到并修改了一个用于生成缩略图的小 php 脚本
$src = (isset($_GET['file']) ? $_GET['file'] : "");
$width = (isset($_GET['maxwidth']) ? $_GET['maxwidth'] : 73);
$thname = "xxx";
$file_extension = substr($src, strrpos($src, '.')+1);
switch(strtolower($file_extension)) {
case "gif": $content_type="image/gif"; break;
case "png": $content_type="image/png"; break;
case "bmp": $content_type="image/bmp"; break;
case "jpeg":
case "jpg": $content_type="image/jpg"; break;
default: $content_type="image/png"; break;
}
if (list($width_orig, $height_orig, $type, $attr) = @getimagesize($src)) {
$height = ($width / $width_orig) * $height_orig;
}
$tn = imagecreatetruecolor($width, $height) ;
$image = imagecreatefromjpeg($src) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($tn, './media/'.$thname.'.'.$file_extension, 90);
它完美地生成和保存缩略图。
如何即时显示这些缩略图?
我试图在脚本的底部添加它
header('Content-Type: image/jpeg');
imagegd($image);
但它说The image cannot be displayed because it contains errors
。我究竟做错了什么?