PbootCms模板默认的图片裁剪是从左上角开始裁剪,使用width,height,maxwidth,maxheight等参数进行调节。 但是裁剪出来的图片始终感觉不是那么令人满意。(也许是我不会用) 比如多人物合影,PB默认的裁剪是左上,那么这个裁剪就会丢掉C位,那怎么能行。 今天来优化一下裁剪图片,让他能简单快捷的裁剪出理想的图片。 我想要的效果是不论横图竖图都是居中裁剪。 翠花,上干货! 解决方案 首先找到裁剪缩略图的方法, 文件位置:/core/function/file.php 搜索:function cut_img,大约在447行 对cut_img方法进行优化,直接上代码: // 剪切图片 function cut_img($src_image, $out_image = null, int $new_width = null, int $new_height = null, $img_quality = 90) { // 输出地址 if (! $out_image) $out_image = $src_image; // 读取配置文件设置 if (! $new_width && ! $new_height) return; // 获取图片属性 list ($width, $height, $type, $attr) = getimagesize($src_image); switch ($type) { case 1: $img = imagecreatefromgif($src_image); break; case 2: $img = imagecreatefromjpeg($src_image); break; case 3: $img = imagecreatefrompng($src_image); break...
内容已隐藏,请关注公众号输入验证码查看
本帖支持关注公众号查看
【无套路 无套路 无套路 扫描二维码关注公众号发送【验证码】收到验证码 在上面输入点击提交查看即可显示隐藏内容】
|