<?php  
/*输入 需要处理图片的 文件名，生成新图片的保存文件名，生成新图片的宽，生成新图片的高*/
 function simage($background,$width,$height,$newfile,$imgtype,$type) { 
 list($s_w,$s_h)=getimagesize($background);//获取原图片高度、宽度
 if($type==1){
 if ($width && ($s_w < $s_h)) {
 $width = ($height / $s_h) * $s_w;
 } else {
 $height = ($width / $s_w) * $s_h;
    };
 };
 $new=imagecreatetruecolor($width,$height);
 switch($imgtype){
 case jpeg:
 $img=imagecreatefromjpeg($background);
 break;
 case jpg:
 $img=imagecreatefromjpeg($background);
 break;
 case png:
 $img=imagecreatefrompng($background);
 break;
 case gif:
 $img=imagecreatefromgif($background);
 break;
 };
 imagecopyresampled($new,$img,0,0,0,0,$width,$height,$s_w,$s_h);
 switch($imgtype){
 case jpeg:
 imagejpeg($new,$newfile);
 break;
 case jpg:
 imagejpeg($new,$newfile);
 break;
 case png:
 imagepng($new,$newfile);
 break;
 case gif:
 imagegif($new,$newfile);
 break;
 };
 imagedestroy($new);
 imagedestroy($img);
  };
?>