You are here

function canvasactions_definecanvas_image in ImageCache Actions 6

Same name and namespace in other branches
  1. 5.3 canvasactions.inc \canvasactions_definecanvas_image()
  2. 5.2 canvasactions.inc \canvasactions_definecanvas_image()
  3. 6.2 canvasactions/canvasactions.inc \canvasactions_definecanvas_image()

Implementation of hook_image()

Creates a solid background canvas

Process the imagecache action on the passed image

Parameters

$image: array defining an image file, including :

$image- >source as the filename,

$image->info array

$image->resource handle on the image object

File

./canvasactions.inc, line 173
Helper functions for the text2canvas action for imagecache

Code

function canvasactions_definecanvas_image(&$image, $action = array()) {

  // May be given either exact or relative dimensions.
  if ($action['exact']['width'] || $action['exact']['width']) {

    // Allows only one dimension to be used if the other is unset.
    if (!$action['exact']['width']) {
      $action['exact']['width'] = $image->info['width'];
    }
    if (!$action['exact']['height']) {
      $action['exact']['height'] = $image->info['height'];
    }
    $targetsize['width'] = _imagecache_percent_filter($action['exact']['width'], $image->info['width']);
    $targetsize['height'] = _imagecache_percent_filter($action['exact']['height'], $image->info['height']);
    $targetsize['left'] = _imagecache_keyword_filter($action['exact']['xpos'], $targetsize['width'], $image->info['width']);
    $targetsize['top'] = _imagecache_keyword_filter($action['exact']['ypos'], $targetsize['height'], $image->info['height']);
  }
  else {

    // calculate relative size
    $targetsize['width'] = $image->info['width'] + $action['relative']['leftdiff'] + $action['relative']['rightdiff'];
    $targetsize['height'] = $image->info['height'] + $action['relative']['topdiff'] + $action['relative']['bottomdiff'];
    $targetsize['left'] = $action['relative']['leftdiff'];
    $targetsize['top'] = $action['relative']['topdiff'];
  }

  // convert from hex (as it is stored in the UI)
  if ($action['RGB']['HEX'] && ($deduced = hex_to_rgb($action['RGB']['HEX']))) {
    $action['RGB'] = array_merge($action['RGB'], $deduced);
  }

  // All the maths is done, now defer to the api toolkits;
  $action['targetsize'] = $targetsize;
  $success = imageapi_toolkit_invoke('definecanvas', $image, array(
    $action,
  ));
  if ($success) {
    $image->info['width'] = $targetsize['width'];
    $image->info['height'] = $targetsize['height'];
  }
  return $success;

  /*

    $newcanvas = imagecreatetruecolor($targetsize['width'], $targetsize['height']);

    if ($RGB['HEX'] && $deduced = hex_to_rgb($RGB['HEX'])) {
      $background = imagecolorallocate($newcanvas, $RGB['red'], $RGB['green'], $RGB['blue']);
    }
    else {
      // No color, attempt transparency, assume white
      $background = imagecolorallocatealpha($newcanvas, 255, 255, 255, 127);
      imagesavealpha($newcanvas, TRUE);
      imagealphablending($newcanvas, FALSE);
      imagesavealpha($image->resource, TRUE);
    }
    imagefilledrectangle($newcanvas, 0, 0, $targetsize['width'], $targetsize['height'], $background);
  #  imagealphablending($newcanvas, TRUE);

    if ($action['under']) {
      $canvas_object = (object) array(
        'resource' => $newcanvas,
        'info' => array(
          'width' => $targetsize['width'],
          'height' => $targetsize['height'],
          'mime_type' => 'image/png',
        ),
        'toolkit' => $image->toolkit,
      );
      imageapi_image_overlay($canvas_object, $image, $targetsize['left'], $targetsize['top'], 100, TRUE);
    }
    else {
      $image->resource = $newcanvas ;
    }
  */
  $image->info['width'] = $targetsize['width'];
  $image->info['height'] = $targetsize['height'];
  return TRUE;
}