Given the following PHP code:
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); } }
To place it in English, we first resize, keeping the aspect ratio so that the smaller edge of the image becomes the desired size, then the resulting image is cropped along the longer edge to $width X $height with equal amounts cut on each (the smaller side does not need cropped).
Is it possible to do this in a single convert command?
source share