views:

166

answers:

1

Hello all, I've been having some trouble generating an image with the Imagick PHP extension. Everything works fine, except my following "montage" has a white background and therefore I cannot overlay it on top of something else. How can I generate a montage with a transparent background?

       $Montage = $Icons->montageImage(new imagickdraw(), "3x2+0+0", "34x34+3+3", imagick::MONTAGEMODE_UNFRAME, "0x0+0+0");
      $Canvas->compositeImage($Montage, $Montage->getImageCompose(), 5, 5);

Thanks!!

+1  A: 

I had the same problem and discovered that the MagickWand C API, which powers imagick), doesn't support the option for montage.

I ended up montaging it manually like this:

// Add them to an array of Imagick objects, instead of using addImage().
$images = new Array();

// Make a transparent canvas.
$target = new Imagick();
$target->newImage($width, $height * count(images), 'none');

$i = 0;
foreach ($images as $image) {
    $target->compositeImage($image, imagick::COMPOSITE_COPY, 0, $height * $i++);
}
Jason
Too bad you have to do this by hand, but at least your advice saved me a serious headache. I needed to montage images in a 2x2 layout but with little adjustement your code snippet is perfectly fit.
Patonza