You are here

function manualcrop_auto_reuse_effect in Manual Crop 7

Image effect callback; Search for a Manual Crop effect with a crop selection and reuse it.

Parameters

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

$data: An array of settings, needed to perform the select effect, with the following items:

  • "fallback_style": The image style to use when no crop selection was found.

Return value

TRUE on success, FALSE on failure to select the effect.

See also

image_crop_effect()

1 string reference to 'manualcrop_auto_reuse_effect'
manualcrop_image_effect_info in ./manualcrop.module
Implements hook_image_effect_info().

File

./manualcrop.module, line 943

Code

function manualcrop_auto_reuse_effect(&$image, $data) {
  if ($style_name = _manualcrop_get_auto_reuse_style_name($image->source, $data)) {

    // Load the style to reuse.
    $style = image_style_load($style_name);
    if (empty($data['apply_all_effects'])) {

      // Apply only the crop effect.
      $effect = reset($style['effects']);
      return image_effect_apply($image, $effect);
    }
    else {

      // Apply all effects.
      foreach ($style['effects'] as $effect) {
        if (!image_effect_apply($image, $effect)) {
          return FALSE;
        }
      }
      return TRUE;
    }
  }
  elseif (!empty($data['fallback_style'])) {

    // Load and apply all effects of the fallback style.
    $style = image_style_load($data['fallback_style']);
    foreach ($style['effects'] as $effect) {
      if (!image_effect_apply($image, $effect)) {
        return FALSE;
      }
    }
  }
  return TRUE;
}