source as the filename, * * $image->info array * * $image->resource handle on the image object * * @param $action array of settings as defined in your form. */ /** * Implementation of hook_imagecache_actions(). * * Declare available actions, return help text about this filter. */ function imagecache_customactions_imagecache_actions() { $actions = array( 'imagecache_customactions' => array( 'name' => t('Custom action'), 'description' => t('Runs custom PHP code'), ), ); return $actions; } /** * * Implementation of imagecache_hook_form() * * @param $action array of settings for this action * @return a form definition */ function imagecache_customactions_form($action) { if ( empty($action) ) { $action = array('text' => 'return $image;'); } $form = array( 'text' => array( '#type' => 'textarea', '#rows' => 10, '#title' => t('Code'), '#default_value' => $action['text'], '#description' => t('

Enter PHP code for your custom action. Source image is available in the $image object which contains an $image->info array, and a $image->resource which is the php toolkit object itself. Your code must return an image object of the same structure (see ImageAPI). For convenience, the images current $image->info variables - $width, $height are available in the current scope.
Do not use %php tags.

If possible, the owning $node object may also be available.

Note that executing incorrect PHP-code can break your Drupal site.

If you are using a WYSIWYG, you must disable it for this edit area.

example:

// Wave an image
  $amplitude = 10; $period = 10;
  $x=0; $y=0;
// Make a copy of the image twice the size
  $height2 = $height * 2; $width2 = $width * 2;
  $img2 = imagecreatetruecolor($width2, $height2);
  imagecopyresampled($img2, $image->resource, 0, 0, $x, $y, $width2, $height2, $width, $height);
// Wave it
  for($i = 0; $i < ($width2); $i += 2)
    imagecopy($img2, $img2, $x+$i-2, $y+sin($i/$period)*$amplitude, $x+$i, $y, 2, $height2);
// Resample it down again
  imagecopyresampled($image->resource, $img2, $x, $y, 0, 0, $width, $height, $width2, $height2);
  imagedestroy($img2);
return $image;

# code modified from bokehman at http://www.sitepoint.com/forums/showpost.php?p=3655457
', array('%php' => '')), '#wysiwyg' => FALSE, ) ); return $form; } /** * Implementation of hook_image() * * @param $image * @param $action */ function imagecache_customactions_image($image, $action) { // Pull the images $width and $height out to play @extract($image->info); // And maybe the owner node data could be useful if (function_exists('imagecache_actions_node_from_filepath')) { $node = imagecache_actions_node_from_filepath($image->source); } $result = eval($action['text']); return $result; } /** * Implementation of theme_hook() for imagecache_ui.module */ function theme_imagecache_customactions($element) { $data = $element['#value']; return "". $data['text'] ."" ; }