如果想真正改变,你看看这个代码(没试验过):
function makethumb($srcfile,$dstfile,$dstw,$dsth) {
$data=getimagesize($srcfile,&$info);
switch (coreutil::getfileextension($dstfile)){
case'gif':
$im= @imagecreatefromgif($srcfile); break;
case'jpg':
case'jpeg':
$im= @imagecreatefromjpeg($srcfile); break;
case'png':
$im= @imagecreatefrompng($srcfile); break;
default:returnfalse;
}
if(!$im) returnfalse;
$srcw=imagesx($im);
$srch=imagesy($im);
$dstx=0;
$dsty=0;
if ($srcw*$dsth>$srch*$dstw){
$fdsth=round($srch*$dstw/$srcw);
$dsty=floor(($dsth-$fdsth)/2); $fdstw=$dstw;
} else {
$fdstw=round($srcw*$dsth/$srch); $dstx=floor(($dstw-$fdstw)/2);
$fdsth=$dsth;
}
$ni=imagecreate($dstw,$dsth);
$dstx=($dstx0)?0:$dstx;
$dsty=($dstx0)?0:$dsty;
$dstx=($dstx>($dstw/2))?floor($dstw/2):$dstx;
$dsty=($dsty>($dsth/2))?floor($dsth/s):$dsty;
$black= imagecolorallocate($ni,0,0,0);
imagefilledrectangle($ni,0,0,$dstw,$dsth,$black);
imagecopyresized($ni,$im,$dstx,$dsty,0,0,$fdstw,$fdsth,$srcw,$srch);
imagejpeg($ni,$dstfile);
imagedestroy($im);
imagedestroy($ni);
returntrue;
}
大概就是用到imagecreatefromjpeg、imagecreatetruecolor、imagecopyresampled 、 imagepng这几个函数