我發現和修飾的小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