skullcap23 has asked for the wisdom of the Perl Monks concerning the following question:

I've been writing a program using imagemagick which makes animated tiled background gifs of lots of objects falling (originally to make a snow effect but it could be anything). I'd like to have them all rendered in different random opacities over the background to get a layered effect, but I can't get the opacity function to work in Image->composite.

I've reproduced the error in the following code (adapted from an earlier reply i found on a similar subject.)

#!/usr/bin/perl -w use strict; use Image::Magick; # Simulate background picture... :) my $image1 = Image::Magick->new; $image1->Set(size=>'100x100'); $image1->ReadImage('xc:orange'); # Textbackground image my $image2 = Image::Magick->new; $image2->ReadImage('testopaq.png'); # Make composite image of background and a 50 % transparent image. $image1->Composite(compose=>'over', image=>$image2, x=>0, y=>0, opacity=>50 ); $image1->Display;

testopaq.png is a black stripe and a white stripe on a transparent background.

with opacity=0 or not stated, it does the normal 'over' overlay, with transparent areas untouched, but with opacity >0, testopaq.png is overlaid with a black background and no effect on opacity. The transparent areas of testopaq.png end up black.

when i use the 'dissolve' option instead of 'over', nothing happens at all, for any value of opacity.

using ImageMagick 5.5.5 and perl 5.6.1

Replies are listed 'Best First'.
Re: Image compositing with opacity not working in perlmagick
by halley (Prior) on Jun 02, 2003 at 18:49 UTC

    You must tell ImageMagick to convert the internal working image into an RGBA buffer before it will composite other RGBA objects onto it properly. Create or load your "background" image with the truecolormatte type. Check my site's Hemera Photo Objects HOWTO script, especially the last bit, for a start on the right road. http://www.halley.cc/ed/linux/interop/hemera.html

    --
    [ e d @ h a l l e y . c c ]

      I just tried adding the lines:

      $image2->Set(type=>"TrueColorMatte"); $image1->Set(type=>"TrueColorMatte");

      before doing the image composition, and it's still not working - however I set the composition mode and opacity, I can't make it do a semitransparent overlay.

      So unless I missed the point of what you were saying, this doesn't seem to be the answer.

      Andy Baxter.