You are here

function imageapi_image_crop in ImageAPI 6

Same name and namespace in other branches
  1. 5 imageapi.module \imageapi_image_crop()

Crop an image to the rectangle specified by the given rectangle.

Parameters

$image: An image object returned by imageapi_image_open().

$x: The top left coordinate, in pixels, of the crop area (x axis value).

$y: The top left coordinate, in pixels, of the crop area (y axis value).

$width: The target width, in pixels.

$height: The target height, in pixels.

Return value

TRUE or FALSE, based on success.

1 call to imageapi_image_crop()
imageapi_image_scale_and_crop in ./imageapi.module
Scales an image to the exact width and height given.

File

./imageapi.module, line 329
An ImageAPI supporting additional image plugins as modules. Images are treated as objects, and images are not written per manipulation as Drupal's core image handling works.

Code

function imageapi_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 imageapi_toolkit_invoke('crop', $image, array(
    $x,
    $y,
    $width,
    $height,
  ));
}