imagecopyresampled()函数
bool imagecopyresampled ( resource dstimage,resource src_image , int dstx,int dst_y , int srcx,int src_y , int dstw,int dst_h , int srcw,int src_h )
$dst_image:新建的图片
$src_image:需要载入的图片
$dst_x:设定需要载入的图片在新图中的x坐标
$dst_y:设定需要载入的图片在新图中的y坐标
$src_x:设定载入图片要载入的区域x坐标
$src_y:设定载入图片要载入的区域y坐标
$dst_w:设定载入的原图的宽度(在此设置缩放)
$dst_h:设定载入的原图的高度(在此设置缩放)
$src_w:原图要载入的宽度
$src_h:原图要载入的高度
For example:
$filename="20151126.jpg";
$percent=0.2;
header("Content-type:image/jpeg");
list($width,$height)=getimagesize($filename);
$newWidth=$width*$percent;
$newHeight=$height*$percent;
$thumb=imagecreatetruecolor($newWidth,$newHeight);
$source=imagecreatefromjpeg($filename);
imagecopyresampled($thumb,$source,0,0,0,0,$newWidth,$newHeight,$width,$height);
imagejpeg($thumb);