You are here

function imagecache_customactions_form in ImageCache Actions 6.2

Same name and namespace in other branches
  1. 8 customactions/imagecache_customactions.module \imagecache_customactions_form()
  2. 6 imagecache_customactions.module \imagecache_customactions_form()
  3. 7 customactions/imagecache_customactions.module \imagecache_customactions_form()

Implementation of imagecache_hook_form()

Parameters

$action array of settings for this action:

Return value

a form definition

File

customactions/imagecache_customactions.module, line 82
Allow advanced users to code their own PHP image manipulation routines as part of imagecache processing.

Code

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('
      <p>Enter PHP code for your custom action. Source image is available in the $image object
      which contains an <code>$image->info</code> array,
      and a <code>$image->resource</code> which is the php toolkit object itself.
      Your code must <b>return</b> an image object of the same structure (see ImageAPI).
      For convenience, the images current <code>$image->info</code> variables
      - <code>$width</code>, <code>$height</code> are available in the current scope.
      <br/>Do not use %php tags. </p>
      <p>If possible, the owning $node object may also be available.</p>
      <p>Note that executing incorrect PHP-code can break your Drupal site.</p>
      <p>If you are using a WYSIWYG, you must disable it for this edit area.</p>
<h3>example:</h3>
<pre style="overflow:auto; background-color:#EEEEEE;padding:0.3em; font-size:0.8em; line-height:1em;">
// 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
</pre>
      ', array(
        '%php' => '<?php ?>',
      )),
      '#wysiwyg' => FALSE,
    ),
  );
  return $form;
}