【发布时间】:2013-09-16 17:18:13
【问题描述】:
给定以下 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 命令中执行此操作?
【问题讨论】:
标签: imagemagick