function bigtosmallimg($file,$path,$w=120,$h=90)
{
$img=$path.$file;
$imgarr=getimagesize($img);
$sw=$imgarr[0];//原图宽
$sh=$imgarr[1];//原图高
$stype=$imgarr[2];
//按比例缩放
if($sw/$sh>$w/$h){
$mw=$w;
$mh=(int)$sh*($w/$sw);
}
else{
$mw=(int)$sw*($h/$sh);
$mh=$h;
}
switch($stype){//根据上传好的图形文件类型新建一个用来生成缩略图的源文件。
case 1:
$srcf = imagecreatefromgif($img);
break;
case 2:
$srcf = imagecreatefromjpeg($img);
break;
case 3:
$srcf = imagecreatefrompng($img);
break;
default:
showmsg('程序调用错误。');
break;
}
$desf =imagecreatetruecolor($mw,$mh);
imagecopyresampled($desf,$srcf,0,0,0,0,$mw,$mh,$sw,$sh);
$sm_name=$path."s_".$file;
switch($stype){
case 1:
imagegif($desf,$sm_name);
break;
case 2:
imagejpeg($desf,$sm_name);
break;
case 3:
imagepng($desf,$sm_name);
break;
default:
showmsg('无法生成www.111com.net' . $stype . '的缩略图。');
break;
}
imagedestroy($desf);
imagedestroy($srcf);
}
|