php 切割图片 坐标,图片以中心区域自动剪裁成固定大小的图片

图片以中心区域自动剪裁成固定大小的图片

有时候在做图片上传的过程中需要对图片进行剪裁,剪裁成我们想要的图片尺寸,如何让图片以中心区域为原点进行剪裁呢?

下面给大家提供一下计算的方法

$org_info[0]:原图宽度 $org_info[1]:原图高度 $thumb_width:新图片宽度 $thumb_height:新图片高度

$dst_x = 0;

$dst_y = 0;

$odst_x = 0;

$odst_y = 0;

if($org_info[0] < $thumb_width && $org_info[1] < $thumb_height)

{

$odst_x = intval(( $thumb_width - $org_info[0])/2);

$odst_y = intval(($thumb_height - $org_info[1] )/2);

}

elseif($org_info[0] < $thumb_width)

{

$odst_x = intval(( $thumb_width - $org_info[0])/2);

$dst_y = intval(($org_info[1] - $thumb_height)/2);

}

elseif($org_info[1] < $thumb_height)

{

$dst_x = intval(($org_info[0] - $thumb_width)/2);

$odst_y = intval(($thumb_height - $org_info[1] )/2);

}else{

$dst_x = intval(($org_info[0] - $thumb_width)/2);

$dst_y = intval(($org_info[1] - $thumb_height)/2);

}

imagecopyresized($img_thumb, $img_org,$odst_x, $odst_y, $dst_x, $dst_y, $org_info[0], $org_info[1], $org_info[0], $org_info[1]);

/* 参数详解 */

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 )

$dst_image:新建的图片

$src_image:需要载入的图片

$dst_x:设定需要载入的图片在新图中的x坐标

$dst_y:设定需要载入的图片在新图中的y坐标

$src_x:设定载入图片要载入的区域x坐标

$src_y:设定载入图片要载入的区域y坐标

$dst_w:设定载入的原图的宽度(在此设置缩放)

$dst_h:设定载入的原图的高度(在此设置缩放)

$src_w:原图要载入的宽度

$src_h:原图要载入的高度

该日志未加标签。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值