You are here

function imagecache_customactions_effect in ImageCache Actions 7

Same name and namespace in other branches
  1. 8 customactions/imagecache_customactions.module \imagecache_customactions_effect()

Image effect callback for the custom action effect.

Parameters

stdClass $image:

array $data:

Return value

boolean true on success, false otherwise.

1 string reference to 'imagecache_customactions_effect'
imagecache_customactions_image_effect_info in customactions/imagecache_customactions.module
Implements hook_image_effect_info().

File

customactions/imagecache_customactions.module, line 158
Allows advanced users to code their own PHP image manipulation routines as part of image style processing.

Code

function imagecache_customactions_effect(stdClass $image, array $data) {
  $result = module_exists('php');
  if ($result) {

    // Get context about the image.
    module_load_include('inc', 'imagecache_actions', 'utility');
    $GLOBALS['image_context'] = imagecache_actions_get_image_context($image, $data);
    $GLOBALS['image'] = $image;

    // Get (non-alterable) context about the image style and image effect.
    $execution_info = imagecache_actions_get_image_effect_context();
    $GLOBALS['image_style'] = $execution_info['image_style'];
    $GLOBALS['image_effect_id'] = $execution_info['image_effect_id'];
    $result = php_eval('<' . '?php global $image, $image_context; ' . $data['php'] . ' ?' . '>');

    // php_eval returns '1' if the snippet returns true.
    $result = $result === '1';
    unset($GLOBALS['image_effect_id']);
    unset($GLOBALS['image_style']);
    unset($GLOBALS['image']);
    unset($GLOBALS['image_context']);
  }
  if ($result && $image->toolkit == 'GD') {
    $image->info['width'] = imagesx($image->resource);
    $image->info['height'] = imagesy($image->resource);
  }
  return $result;
}