$maxwidth) || ($maxheight && $pic_height > $maxheight)){ if($maxwidth && $pic_width>$maxwidth){ $widthratio = $maxwidth/$pic_width; $resizewidth_tag = true; } if($maxheight && $pic_height>$maxheight){ $heightratio = $maxheight/$pic_height; $resizeheight_tag = true; } if($resizewidth_tag && $resizeheight_tag){ if($widthratio<$heightratio) $ratio = $widthratio; else $ratio = $heightratio; } if($resizewidth_tag && !$resizeheight_tag) $ratio = $widthratio; if($resizeheight_tag && !$resizewidth_tag) $ratio = $heightratio; $newwidth = $pic_width * $ratio; $newheight = $pic_height * $ratio; if(function_exists("imagecopyresampled")){ $newim = imagecreatetruecolor($newwidth,$newheight);//PHP系统函数 imagecopyresampled($newim,$im,0,0,0,0,$newwidth,$newheight,$pic_width,$pic_height);//PHP系统函数 } else{ $newim = imagecreate($newwidth,$newheight); imagecopyresized($newim,$im,0,0,0,0,$newwidth,$newheight,$pic_width,$pic_height); } $name = $name.".".$filetype; if( !strcasecmp($filetype,"jpg") || !strcasecmp($filetype,"jpeg") ){ imagejpeg($newim,$name); } else if( !strcasecmp($filetype,"png") ){ imagepng($newim,$name); } // else if( !strcasecmp($filetype,"gif") ){ //不处理GIF文件因为压缩后就不会动了,开注释可处理 // imagegif($newim,$name); // } imagedestroy($newim); } else{ //原图小于设定的最大长度和宽度,则不进行压缩,原图输出 $name = $name.".".$filetype; if( !strcasecmp($filetype,"jpg") && !strcasecmp($filetype,"jpeg") ){ imagejpeg($im,$name); } else if( !strcasecmp($filetype,"png") ){ imagepng($im,$name); } // else if( !strcasecmp($filetype,"gif") ){ //不处理GIF文件因为压缩后就不会动了,开注释可处理 // imagegif($im,$name); // } } } }