给出以下
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,每边切割的数量相等(较小的一侧不需要裁剪).
是否可以在单个转换命令中执行此操作?