You are here

function canvasactions_definecanvas_image in ImageCache Actions 6.2

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 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/canvasactions.inc, line 307

Code

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

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

    // 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 = imagecache_actions_hex2rgba($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;
}