function canvasactions_definecanvas_effect in ImageCache Actions 8
Same name and namespace in other branches
- 7 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 312
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'];
}
$targetsize['width'] = imagecache_actions_percent_filter($data['exact']['width'], $image->info['width']);
$targetsize['height'] = imagecache_actions_percent_filter($data['exact']['height'], $image->info['height']);
$targetsize['left'] = image_filter_keyword($data['exact']['xpos'], $targetsize['width'], $image->info['width']);
$targetsize['top'] = image_filter_keyword($data['exact']['ypos'], $targetsize['height'], $image->info['height']);
}
else {
// Calculate relative size.
$targetsize['width'] = $image->info['width'] + $data['relative']['leftdiff'] + $data['relative']['rightdiff'];
$targetsize['height'] = $image->info['height'] + $data['relative']['topdiff'] + $data['relative']['bottomdiff'];
$targetsize['left'] = $data['relative']['leftdiff'];
$targetsize['top'] = $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'] = $targetsize;
$success = image_toolkit_invoke('definecanvas', $image, array(
$data,
));
if ($success) {
$image->info['width'] = $targetsize['width'];
$image->info['height'] = $targetsize['height'];
}
return $success;
}