You are here

function simplecrop_crop_effect_callback in SimpleCrop 7

Crops image to a selected area.

1 string reference to 'simplecrop_crop_effect_callback'
simplecrop_image_effect_info in includes/simplecrop.effects.inc
Implements hook_image_effect_info().

File

includes/simplecrop.effects.inc, line 25
Contains definition and implementation of new image style effects.

Code

function simplecrop_crop_effect_callback(&$image) {

  // Try to find a crop for this image.
  $crop = simplecrop_crop_load($image->source);

  // If crop doesn't exists then nothing to do here.
  if (empty($crop) || empty($crop->data)) {
    return TRUE;
  }

  // Calculate a crop resolution based on given coordinates.
  $width = abs($crop->data['x'] - $crop->data['x2']);
  $height = abs($crop->data['y'] - $crop->data['y2']);

  // If width or height is 0, then we don't need to crop
  // anything, so just return success status.
  if (!$width || !$height) {
    return TRUE;
  }

  // Try to crop image.
  if (!image_crop($image, $crop->data['x'], $crop->data['y'], $width, $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;
}