You are here

function canvasactions_definecanvas_dimensions in ImageCache Actions 7

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

Image dimensions callback for the define canvas effect.

Parameters

array $dimensions: Dimensions to be modified - an associative array containing the items 'width' and 'height' (in pixels).

array $data: An associative array containing the effect data.

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

File

canvasactions/canvasactions.inc, line 445

Code

function canvasactions_definecanvas_dimensions(array &$dimensions, 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'] = $dimensions['width'];
    }
    if (!$data['exact']['height']) {
      $data['exact']['height'] = $dimensions['height'];
    }
    $dimensions['width'] = imagecache_actions_percent_filter($data['exact']['width'], $dimensions['width']);
    $dimensions['height'] = imagecache_actions_percent_filter($data['exact']['height'], $dimensions['height']);
  }
  else {

    // Calculate relative sizes (only possible if we have the current size).
    if ($dimensions['width'] !== NULL) {
      $dimensions['width'] = $dimensions['width'] + (int) $data['relative']['leftdiff'] + (int) $data['relative']['rightdiff'];
    }
    if ($dimensions['height'] !== NULL) {
      $dimensions['height'] = $dimensions['height'] + (int) $data['relative']['topdiff'] + (int) $data['relative']['bottomdiff'];
    }
  }
}