You are here

function canvasactions_definecanvas_effect in ImageCache Actions 7

Same name and namespace in other branches
  1. 8 canvasactions/canvasactions.inc \canvasactions_definecanvas_effect()

Image effect callback for the define canvas effect.

Parameters

stdClass $image:

array $data:

Return value

boolean true on success, false otherwise.

1 string reference to 'canvasactions_definecanvas_effect'
imagecache_canvasactions_image_effect_info in canvasactions/imagecache_canvasactions.module
Implements hook_image_effect_info().

File

canvasactions/canvasactions.inc, line 314

Code

function canvasactions_definecanvas_effect(stdClass $image, array $data) {

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

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

    // Calculate relative size.
    $target_size['width'] = $image->info['width'] + (int) $data['relative']['leftdiff'] + (int) $data['relative']['rightdiff'];
    $target_size['height'] = $image->info['height'] + (int) $data['relative']['topdiff'] + (int) $data['relative']['bottomdiff'];
    $target_size['left'] = (int) $data['relative']['leftdiff'];
    $target_size['top'] = (int) $data['relative']['topdiff'];
  }

  // Convert from hex (as it is stored in the UI).
  if ($data['RGB']['HEX'] && ($deduced = imagecache_actions_hex2rgba($data['RGB']['HEX']))) {
    $data['RGB'] = array_merge($data['RGB'], $deduced);
  }

  // All the math is done, now defer to the toolkit in use.
  $data['targetsize'] = $target_size;
  $success = image_toolkit_invoke('definecanvas', $image, array(
    $data,
  ));
  if ($success) {
    $image->info['width'] = $target_size['width'];
    $image->info['height'] = $target_size['height'];
  }
  return $success;
}