| 
				
					| 缩图黑边问题解决办法 
 
							
								| 如果设置的缩图超出部分不截取的话,缩出的图会变形。 修改下可以同比例缩小,黑边的问题也一并解决了。
 
 用下面的代码替换 e/class/gd.php 中的相同函数即可。
 同时将 系统参数设置 -  图片设置  选项卡 中的 超出部分是否截取 设置为 否
 
 
 
 //原文件,新文件,宽度,高度,维持比例
 function ResizeImage($big_image_name, $new_name, $max_width = 400, $max_height = 400, $resize = 1){
 $returnr['file']='';
 $returnr['filetype']='';
 if($temp_img_type = @getimagesize($big_image_name)) {eregi('/([a-z]+)$', $temp_img_type[mime], $tpn); $img_type = $tpn[1];}
 else {eregi('.([a-z]+)$', $big_image_name, $tpn); $img_type = $tpn[1];}
 $all_type = array(
 "jpg"   => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg"  , "exn"=>".jpg"),
 "gif"   => array("create"=>"ImageCreateFromGIF" , "output"=>"imagegif"   , "exn"=>".gif"),
 "jpeg"  => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg"  , "exn"=>".jpg"),
 "png"   => array("create"=>"imagecreatefrompng" , "output"=>"imagepng"   , "exn"=>".png"),
 "wbmp"  => array("create"=>"imagecreatefromwbmp", "output"=>"image2wbmp" , "exn"=>".wbmp")
 );
 
 $func_create = $all_type[$img_type]['create'];
 if(empty($func_create) or !function_exists($func_create))
 {
 return $returnr;
 }
 //输出
 $func_output = $all_type[$img_type]['output'];
 $func_exname = $all_type[$img_type]['exn'];
 if(($func_exname=='.gif'||$func_exname=='.png'||$func_exname=='.wbmp')&&!function_exists($func_output))
 {
 $func_output='imagejpeg';
 $func_exname='.jpg';
 }
 $big_image   = $func_create($big_image_name);
 $big_width   = imagesx($big_image);
 $big_height  = imagesy($big_image);
 if($big_width <= $max_width and $big_height <= $max_height)//如果上传图片尺寸小于缩图 返回
 {
 $func_output($big_image, $new_name.$func_exname);
 $returnr['file']=$new_name.$func_exname;
 $returnr['filetype']=$func_exname;
 return $returnr;
 }
 
 if($resize == 1) {//切图
 if($big_width >= $max_width and $big_height >= $max_height)
 {
 $ratiow      = $max_width  / $big_width;
 $ratioh      = $max_height / $big_height;
 if($big_width > $big_height)
 {
 $tempx  = $max_width / $ratioh;
 $tempy  = $big_height;
 $srcX   = ($big_width - $tempx) / 2;
 $srcY   = 0;
 } else {
 $tempy  = $max_height / $ratiow;
 $tempx  = $big_width;
 $srcY   = ($big_height - $tempy) / 2;
 $srcX   = 0;
 }
 } else {
 if($big_width > $big_height)
 {
 $tempx  = $max_width;
 $tempy  = $big_height;
 $srcX   = ($big_width - $tempx) / 2;
 $srcY   = 0;
 } else {
 $tempy  = $max_height;
 $tempx  = $big_width;
 $srcY   = ($big_height - $tempy) / 2;
 $srcX   = 0;
 }
 }
 $new_width  = ($ratiow  > 1) ? $big_width  : $max_width;
 $new_height = ($ratioh  > 1) ? $big_height : $max_height;
 if(function_exists("imagecopyresampled"))
 {
 $temp_image = imagecreatetruecolor($new_width, $new_height);
 imagecopyresampled($temp_image, $big_image, 0, 0, $srcX, $srcY, $new_width, $new_height, $tempx, $tempy);
 } else {
 $temp_image = imagecreate($new_width, $new_height);
 imagecopyresized($temp_image, $big_image, 0, 0, $srcX, $srcY, $new_width, $new_height, $tempx, $tempy);
 }
 $func_output($temp_image, $new_name.$func_exname);
 }
 else
 {//不切图
 $ratio1=round($big_width/$big_height,2);
 $ratio2=round($max_width/$max_height,2);
 if($ratio1>$ratio2||$ratio1==$ratio2) {
 $ratio=$max_width/$big_width;
 }
 if($ratio1<$ratio2)        {
 $ratio=$max_height/$big_height;
 }
 $temp_w=intval($big_width*$ratio);
 $temp_h=intval($big_height*$ratio);
 $temp_img=imagecreatetruecolor($temp_w,$temp_h);
 if(function_exists("imagecopyresampled")){
 $temp_img=imagecreatetruecolor($temp_w,$temp_h);
 imagecopyresampled($temp_img,$big_image,0,0,0,0,$temp_w,$temp_h,$big_width,$big_height);
 }
 else{
 $temp_image=imagecreate($temp_w, $temp_h);
 imagecopyresized($temp_img,$big_image,0,0,0,0,$temp_w,$temp_h,$big_width,$big_height);
 }
 $bg=imagecreatetruecolor($max_width,$max_height);
 $white = imagecolorallocate($bg,255,255,255);
 imagefill($bg,0,0,$white);
 if($ratio1>$ratio2){
 $x=0;
 $y=($max_height-$temp_h)/2;
 }
 if($ratio1<$ratio2){
 $x=($max_width-$temp_w)/2;
 $y=0;
 }
 imagecopymerge($bg,$temp_img,$x,$y,0,0,$temp_w,$temp_h,100);
 $func_output($bg, $new_name.$func_exname);
 imagedestroy($bg);
 }
 ImageDestroy($big_image);
 ImageDestroy($temp_image);
 $returnr['file']=$new_name.$func_exname;
 $returnr['filetype']=$func_exname;
 return $returnr;
 }
 
 
 
 上传以下附件:
 [下载 *.rar](文件大小:2.89 KB,下载次数:149)
 |  
 
 帝国模板定制,功能开发等  http://ecmsjz.cn
 不在线可QQ  8686588  留言,上线必回。
 
 |  |