生成縮略圖$tx=GetImageSize($sample); if($tx[0]<=$tx[1] and $tx[1]>=120){ $height=120; $width=intval($height*$tx[0]/$tx[1]); } if($tx[0]>=$tx[1] and $tx[0]>=100){ $width=100; $height=intval($width*$tx[1]/$tx[0]); } if($tx[0]<100 and $tx[1]<120){ $width=$tx[0]; $height=$tx[1]; }
makethumb2($sample,$target,$width,$height);
// $srcFile: 源文件 // $dstFile: 目標(biāo)文件 // $dstW: 目標(biāo)圖片寬度 // $dstH: 目標(biāo)文件高度 function makethumb2($srcFile,$dstFile,$dstW,$dstH){ $data=GetImageSize($srcFile,&$info); switch($data[2]){ case 1: $im=@ImageCreateFromGIF($srcFile); break; case 2: $im=@ImageCreateFromJPEG($srcFile); break; case 3: $im=@ImageCreateFromPNG($srcFile); break; } $srcW=ImageSX($im); $srcH=ImageSY($im); $ni=ImageCreate($dstW,$dstH); ImageCopyResized($ni,$im,0,0,0,0,$dstW,$dstH,$srcW,$srcH); ImageJpeg($ni,$dstFile); // 如果需要輸出到瀏覽器,那么將上一句改為ImageJpeg($ni); // 如果需要其它格式的圖片,改動最后一句就可以了 }
|