Page 1 of 1

Transparent PNGs and Composite()

Posted: 2006-12-10T23:06:30-07:00
by johnoyler

Code: Select all

 @$image = ();
 $x = $image->Read('pshadow.png');
 warn "$x" if "$x";
 $x = $final->Composite(compose=>'over', image=>$image);
This is the relevant portion. $final is the image I intend to write out, but both images have transparent portions. $image, which I'm attempting to lay over the top of the final, only does so on those portions where a mask from a previous composite allows. How can I force this to use $image's alpha channel as a mask? If I cook up such a mask in Gimp, and manually use that, it works as expected, but this is a little obtuse, and I have too many utility images already to be adding another one without good reason.

Any help appreciated, thanks in advance.

I see responses on others' posts...

Posted: 2006-12-12T12:54:54-07:00
by johnoyler
Have I not supplied enough information? Not the correct information? Have I described my problem poorly?

Update:

Posted: 2006-12-13T15:00:54-07:00
by johnoyler
If I simply load $final, and then composite $image over the top of it (and nothing else before that), this works as expected. Unfortunately, I've completed several other composites and resizes prior to this.

I thought that it might be that I was re-using image, as I loaded several different files, and then composited them together. But giving this it's own new IM object, and using it only to load the one file, no effect. Still doesn't work.

So it's screwy because $final isn't fresh somehow. Short of writing it out to file, and re-opening it with a new variable, is there any way to make this work?

Posted: 2007-01-03T17:03:52-07:00
by anthony
composite requires at least two images, the destination or background image ($final) and the source or overlay image ($image). Both need to be defined, even if one is not used (Src, Dst, Clear compose methods).

Usally if you want to keep your original destination image, you would make a clone of it first.