function image_crop

7.x image.inc image_crop(stdClass $image, $x, $y, $width, $height)
6.x image.inc image_crop($source, $destination, $x, $y, $width, $height)

Crops an image to a rectangle specified by the given dimensions.

Parameters

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

$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 on success, FALSE on failure.

See also

image_load()

image_scale_and_crop()

image_gd_crop()

Related topics

3 calls to image_crop()
ImageToolkitUnitTest::testCrop in drupal-7.x/modules/simpletest/tests/image.test
Test the image_crop() function.
image_crop_effect in drupal-7.x/modules/image/image.effects.inc
Image effect callback; Crop an image resource.
image_scale_and_crop in drupal-7.x/includes/image.inc
Scales an image to the exact width and height given.
4 string references to 'image_crop'
hook_image_effect_info_alter in drupal-7.x/modules/image/image.api.php
Alter the information provided in hook_image_effect_info().
ImageAdminStylesUnitTest::testStyle in drupal-7.x/modules/image/image.test
General test to add a style, add/remove/edit effects to it, then delete it.
ImageDimensionsTestCase::testImageDimensions in drupal-7.x/modules/image/image.test
Test styled image dimensions cumulatively.
image_image_effect_info in drupal-7.x/modules/image/image.effects.inc
Implements hook_image_effect_info().

File

drupal-7.x/includes/image.inc, line 331
API for manipulating images.

Code

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