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.111cn.net' . $stype . '的縮圖。'); break; } imagedestroy($desf); imagedestroy($srcf); } |