function canvasactions_definecanvas_image in ImageCache Actions 5.2
Same name and namespace in other branches
- 5.3 canvasactions.inc \canvasactions_definecanvas_image()
- 6.2 canvasactions/canvasactions.inc \canvasactions_definecanvas_image()
- 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.inc, line 140
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'];
}
$newcanvas = imagecreatetruecolor($targetsize['width'], $targetsize['height']);
$RGB = $action['RGB'];
// convert from hex (as it is stored in the UI)
if ($RGB['HEX'] && ($deduced = hex_to_rgb($RGB['HEX']))) {
$RGB = array_merge($RGB, $deduced);
}
if ($RGB['red'] || $RGB['green'] || $RGB['blue']) {
// one may be zero...
$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);
if ($action['under']) {
require_once 'watermark.inc';
$watermark = new watermark();
$image->resource = $watermark
->create_watermark($newcanvas, $image->resource, $targetsize['left'], $targetsize['top'], 100);
imagesavealpha($image->resource, TRUE);
}
else {
$image->resource = $newcanvas;
}
$image->info['width'] = $targetsize['width'];
$image->info['height'] = $targetsize['height'];
return TRUE;
}