function imageapi_gd_image_definecanvas in ImageCache Actions 6
Same name and namespace in other branches
- 6.2 canvasactions/canvasactions.inc \imageapi_gd_image_definecanvas()
Draw a color (or transparency) behind an image
$targetsize is an array expected to contain a width,height and a left,top offset.
File
- ./
canvasactions.inc, line 255 - Helper functions for the text2canvas action for imagecache
Code
function imageapi_gd_image_definecanvas(&$image, $action = array()) {
$targetsize = $action['targetsize'];
$RGB = $action['RGB'];
$newcanvas = imagecreatetruecolor($targetsize['width'], $targetsize['height']);
if ($RGB['HEX']) {
$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);
# imagealphablending($newcanvas, TRUE);
if ($action['under']) {
$canvas_object = (object) array(
'resource' => $newcanvas,
'info' => array(
'width' => $targetsize['width'],
'height' => $targetsize['height'],
'mime_type' => $image->info['mime_type'],
'extension' => $image->info['extension'],
),
'toolkit' => $image->toolkit,
);
imageapi_image_overlay($canvas_object, $image, $targetsize['left'], $targetsize['top'], 100, TRUE);
}
else {
$image->resource = $newcanvas;
}
return TRUE;
}