首頁 > php教程 > php手册 > php做缩略图源码

php做缩略图源码

WBOY
發布: 2016-06-06 19:52:21
原創
1419 人瀏覽過

thump.php: ?php include_once('extra.php'); $path='assets/'; $new_height=800; $dir='E:\webroot\blog\test\assets\\'; define("END", "\n"); define("TUD",$dir); function thumb($source,$new_height) { list($im_width, $im_height, $type) = getimage

thump.php:

include_once('extra.php');
$path='assets/';
$new_height=800;
$dir='E:\webroot\blog\test\assets\\';
define("END", "\n");
define("TUD",$dir);
function thumb($source,$new_height)
{
list($im_width, $im_height, $type) = getimagesize($source);
/*$file=explode('/',$source);
$file=array_pop($file);*/

$file=basename($source);
echo $file;


if (!is_writable($source)) {
trigger_error('dir can\'t be write');
//touch('thumb');
}
$new_width=$im_width * $new_height / $im_height;
$new_width=sprintf('%d',round($new_width));
echo $new_width;
$im = ImageCreatefromJpeg($source);
if (!$im)
throw new Exception('Unable to read image file');
$thumb = ImageCreateTrueColor($new_width, $new_height);
ImageCopyResampled($thumb, $im, 0, 0, 0, 0, $new_width, $new_height, $im_width, $im_height);
if (!Imagejpeg($thumb,'thumb/'.$file))
throw new Exception('缩略图失败');
imagedestroy($im);
imagedestroy($thumb);
unlink (TUD.$file);
//echo TUD.$file.' done';
}
$data=enterDir(TUD);
//print_r ($data);
foreach($data as $v)
//echo $v;
thumb(TUD.$v,$new_height);
/*$handle = opendir('thumb/');
while(false !== ($file = readdir($handle))) {
$source="thumb/".$file;
echo "$file
";
}*/
?>
extra.php:

function enterDir($path)
{

if ($handle = opendir($path)) {
$data=array();
    while (false !== ($f = readdir($handle))) {
$ep=array('.','..');
//$ext=substr($f,-3,3);
if (in_array($f,$ep))
continue;
//if (filesize($path.$f)//if (substr($f,0,3)!='000' || substr($f,0,3)!='2003')
// continue;
        $data[]=$f;
    }

/* $result=implode("\t\n",$data);
echo $result;*/
    closedir($handle);


return $data;
}
}
$data=enterDir('E:\webroot\blog\test\assets\\');
print_r($data);
foreach ($data as $k=>$v) {
$title=substr($v,0,-4);
$data[$k]='';
//echo $v;
}
$data=implode("\r\n",$data);
echo $data;

/*function ()
{

}
*/

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板