function image_crop_effect

Image effect callback; Crop an image resource.

Parameters

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

$data: An array of attributes to use when performing the crop effect with the following items:

  • "width": An integer representing the desired width in pixels.
  • "height": An integer representing the desired height in pixels.
  • "anchor": A string describing where the crop should originate in the form of "XOFFSET-YOFFSET". XOFFSET is either a number of pixels or "left", "center", "right" and YOFFSET is either a number of pixels or "top", "center", "bottom".

Return value

TRUE on success. FALSE on failure to crop image.

See also

image_crop()

1 call to image_crop_effect()
ImageEffectsUnitTest::testCropEffect in modules/image/image.test
Test the image_crop_effect() function.
1 string reference to 'image_crop_effect'
image_image_effect_info in modules/image/image.effects.inc
Implements hook_image_effect_info().

File

modules/image/image.effects.inc, line 177

Code

function image_crop_effect(&$image, $data) {
    // Set sane default values.
    $data += array(
        'anchor' => 'center-center',
    );
    list($x, $y) = explode('-', $data['anchor']);
    $x = image_filter_keyword($x, $image->info['width'], $data['width']);
    $y = image_filter_keyword($y, $image->info['height'], $data['height']);
    if (!image_crop($image, $x, $y, $data['width'], $data['height'])) {
        watchdog('image', 'Image crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array(
            '%toolkit' => $image->toolkit,
            '%path' => $image->source,
            '%mimetype' => $image->info['mime_type'],
            '%dimensions' => $image->info['width'] . 'x' . $image->info['height'],
        ), WATCHDOG_ERROR);
        return FALSE;
    }
    return TRUE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.