给定以下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命令中完成此操作?
发布于 2013-09-12 19:32:39
我相信答案是convert "$input" -resize "${width}x${height}^" -gravity center -crop "${width}x${height}+0+0" $output。
https://stackoverflow.com/questions/18762252
复制相似问题