给出以下PHP代码:
function image_scale_and_crop(stdClass $image, $width, $height) {
$scale = max($width / $image->info['width'], $height / $image->info['height']);
$x = ($image->info['width'] * $scale - $width) / 2;
$y = ($image->info['height'] * $scale - $height) / 2;
if (image_resize($image, $image->info['width'] * $scale, $image->info['height'] * $scale)) {
return image_crop($image, $x, $y, $width, $height);
}
}
用英语来说,首先我们要进行调整以保持宽高比,以使图像的较小边缘变为所需的尺寸,然后沿着较长的边缘裁切得到的图像,$width X $height
并在每一侧均进行等量切割(较小的一面会不需要裁剪)。
是否可以在单个convert
命令中执行此操作?
我相信答案是convert "$input" -resize "${width}x${height}^" -gravity center -crop "${width}x${height}+0+0" $output
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句