function imageapi_imagemagick_image_overlay in ImageCache Actions 6
Improvements on this are welcomed!
Please be aware of the limitations of imagemagick libraries out there - the versions distributed on hosted servers (if any) are often several years behind. Using the latest imagemagick release features will make this function unusable in real deployments.
File
- ./
imagecache_canvasactions.module, line 214 - A collection of canvas (layer) type manipulations for imagecache - including "Watermark"
Code
function imageapi_imagemagick_image_overlay(&$image, &$layer, $x = 0, $y = 0, $alpha = 100, $reverse = FALSE) {
$layer_filepath = $layer->source;
# TODO - alpha channels
# I spent ages on the docs, but it appears my version of convert does not support -merge, -watermark or -dissolve
// Bloody libraries - I tried [6.2.8 06/11/08] because that's what I could get for my distro.
// Set its offset. Offset arguments require a sign in front.
if ($x >= 0) {
$x = "+{$x}";
}
if ($y >= 0) {
$y = "+{$y}";
}
# This just drops the image on, no alpha:
if ($alpha == 100) {
$image->ops[] = " \"{$layer_filepath}\" -geometry {$x}{$y} -composite ";
}
else {
$compose_arg = " ";
# $compose_arg = " -compose dissolve ";
// -compose dissolve is supposed to work, but doesn't in available imagemagick versions
$geometry_arg = "-geometry {$x}{$y}";
$alpha_arg = "-set \"option:compose:args\" {$alpha}";
$image->ops[] = " \"{$layer_filepath}\" {$compose_arg} {$geometry_arg} {$alpha_arg} -composite ";
}
# watchdog('imagecache_canvas', print_r($image->ops, 1) );
# This also worked
# $image->ops[] = ' -draw "image over {$x},{$y} 0,0 \'{$layer_filepath}\'"' ;
// TODO - I may end up with a different sized image from doing this?
return TRUE;
}