我发现和修饰的小PHP脚本用于生成缩略图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);
它生成和完美保存缩略图。
如何在飞行中显示这些缩略图?
我tryed到一个脚本
header('Content-Type: image/jpeg');
imagegd($image);
的底部添加这一点,但它说The image cannot be displayed because it contains errors
。我究竟做错了什么?
查找范围中使用文本编辑器图像的源代码;那里你可能会有一个PHP错误信息。 – 2012-07-31 11:47:50
正如我所说:“它完全生成并保存缩略图” – Goldie 2012-07-31 11:49:56
嗯,所以你将这个代码添加到了HTML页面。那不行;您需要将每个结果嵌入''标签中。您可以使用DATA URI来动态显示它们,但在Internet Explorer中不能正常工作,而且在旧版本中根本无法正常工作 – 2012-07-31 11:55:54