bool imagecopyresampled ( resource $dst_image, resource $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_w, int $dst_h, int $src_w, int $src_h)
代码部分:
1 <?php 2 suofang('./yz.jpg',200,100); 3 //只能缩放 jpg的图像 自己进行类型判断 4 function suofang($srcpath,$width = 100,$height = 100){ 5 $srcinfo = getimagesize($srcpath); 6 //计算缩放后的宽高 按比例 7 if($srcinfo[0] > $srcinfo[1]){ //宽 > 高 按宽的比例计算高 8 $height = $srcinfo[1] * ($width/$srcinfo[0]); 9 }else{ 10 //高 > 宽 按高的比例计算宽 11 $width = $srcinfo[0] * ($height/$srcinfo[1]); 12 } 13 //目标资源 空白画布 14 $dstim = imagecreatetruecolor($width,$height); 15 //要缩放的图像 源资源 16 $srcim = imagecreatefromjpeg($srcpath); 17 imagecopyresampled($dstim,$srcim,0,0,0,0,$width,$height,$srcinfo[0],$srcinfo[1]); 18 //保存缩放后的图像 19 imagejpeg($dstim,$suopath); 20 imagedestroy($dstim); 21 imagedestroy($srcim); 22 return $suopath; 23 }