You are here

function imageapi_image_crop in ImageAPI 5

Same name and namespace in other branches
  1. 6 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 323
An ImageAPI supporting mulitple image toolkits. Image toolkits are implemented as modules. Images are objects, but have no methods

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,
  ));
}