分类:
2009-04-29 17:03:51
// 说明:摘录自 AutoIndex 的缩略图显示函数 // 整理: //显示缩略图核心函数 function display_thumbnail($file, $thumbnail_height) { global $html_heading; if (!@is_file($file)) { header('HTTP/1.0 404 Not Found'); die("$html_headingFile not found: "
.htmlentities($file).''); } switch (ext($file)) { case 'gif': $src = @imagecreatefromgif($file); break; case 'jpeg': case 'jpg': case 'jpe': $src = @imagecreatefromjpeg($file); break; case 'png': $src = @imagecreatefrompng($file); break; default: die("$html_headingUnsupported file extension.
"); } if ($src === false) { die("$html_headingUnsupported image type.
"); } header('Content-Type: image/jpeg'); header('Cache-Control: public, max-age=3600, must-revalidate'); header('Expires: '.gmdate('D, d M Y H:i:s', time()+3600).' GMT'); $src_height = imagesy($src); if ($src_height <= $thumbnail_height) { imagejpeg($src, '', 100); } else { $src_width = imagesx($src); $thumb_width = $thumbnail_height * ($src_width / $src_height); $thumb = imagecreatetruecolor($thumb_width, $thumbnail_height); imagecopyresampled($thumb, $src, 0, 0, 0, 0, $thumb_width, $thumbnail_height, $src_width, $src_height); imagejpeg($thumb, '', 100); imagedestroy($thumb); } imagedestroy($src); die(); } //获取文件扩展名 function ext($fn) //return the lowercase file extension of $fn, not including the leading dot { $fn = get_basename($fn); return (strpos($fn, '.') ? strtolower(substr(strrchr($fn, '.'), 1)) : ''); } //获取完整文件名 function get_basename($fn) //returns everything after the slash, or the original string if there is no slash { return basename(str_replace('\\', '/', $fn)); } //调用方式 参数(图片名,缩略图最大高度) display_thumbnail('newwebpick.com.jpg', '200'); ?>