|  | 
 
 发表于 2010-9-8 06:04:23
|
显示全部楼层 
| 我觉得可以用PHP内置的函数 推荐先获取原图的尺寸。然后按照等比的算式算一下需要的小尺寸
 然后用PHP的缩略图函数即可。
 
 这个是我写的一个方法
 function make_thumb_img($file_url='',$max_width=0,$max_height=0)
 {
 $ext = strtolower(end(explode('.',$file_url)));
 if ($ext == 'jpg'|| $ext == 'jpeg') {
 $img = imagecreatefromjpeg($file_url);
 } else if ($ext == 'png') {
 $img = imagecreatefrompng($file_url);
 } else if ($ext == 'gif') {
 $img = imagecreatefrompng($file_url);
 }
 $width=imagesx($img);
 $height=imagesy($img);
 
 if($max_width!=0 && $max_height==0)
 {
 $x=$max_width;
 $y=ceil($x*$height/$width);
 }
 else if($max_width==0 && $max_height!=0)
 {
 $y=$max_height;
 $x=ceil($y*$width/$height);
 }
 
 $dst=imagecreatetruecolor($x,$y);
 imagecopyresampled($dst,$img,0,0,0,0,$x,$y,$width,$height);
 
 header('Content-type: image/png');
 imagepng($dst);
 }
 | 
 |