phptransparencyimagickmontage

Imagick PHP Extension -- Montage help?


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!!


Solution

  • 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++);
    }