Crops an image to a rectangle specified by the given dimensions.
$image: An image object returned by image_load().
int $x: The top left coordinate, in pixels, of the crop area (x axis value).
int $y: The top left coordinate, in pixels, of the crop area (y axis value).
int $width: The target width, in pixels.
int $height: The target height, in pixels.
bool TRUE on success, FALSE on failure.
\Drupal\system\Plugin\ImageToolkitInterface::crop()
function image_crop($image, $x, $y, $width, $height) {
$aspect = $image->info['height'] / $image->info['width'];
if (empty($height)) {
$height = $width / $aspect;
}
if (empty($width)) {
$width = $height * $aspect;
}
$width = (int) round($width);
$height = (int) round($height);
return $image->toolkit
->crop($image, $x, $y, $width, $height);
}