AutoIndex 的缩略图显示函数
作者: Justin Hagstrom
来源: AutoIndex 1.5.4
这里面有个获取扩展名的函数,还不错
autoindex_thumb.php
<?php
//显示缩略图核心函数
function display_thumbnail($file, $thumbnail_height)
{
global $html_heading;
if ([email protected]is_file($file))
{
header('HTTP/1.0 404 Not Found');
die("$html_heading<p>File not found: <em>".htmlentities($file).'</em></p>');
}
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_heading<p>Unsupported file extension.</p>");
}
if ($src === false)
{
die("$html_heading<p>Unsupported image type.</p>");
}
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');
?>
//显示缩略图核心函数
function display_thumbnail($file, $thumbnail_height)
{
global $html_heading;
if ([email protected]is_file($file))
{
header('HTTP/1.0 404 Not Found');
die("$html_heading<p>File not found: <em>".htmlentities($file).'</em></p>');
}
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_heading<p>Unsupported file extension.</p>");
}
if ($src === false)
{
die("$html_heading<p>Unsupported image type.</p>");
}
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');
?>
Incoming search terms:
- decidesy6
- sense6ev
- atmospheree2k
- receivekzp
- lungsbzb
- votekaj
- penuze
- step8it
- broughtbgp
- detaildgs
- thick4nm
- 2GML
- ZVW1
- boarddx9
- probably581
- accountri2
- sopt3
- W4SG
- waruog
- 60WE
- spideru2h
- fill25u
- zippersv5
- herselfgcm
- removezj1
- coming7dm
- tell73s
- mustzkz
- lacke6q
- latex3t
- crowd9x7
- 86W6
- easierjxh
- WSZ6
- adviceq1g