Transparent PNGs and Composite()

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
johnoyler

Transparent PNGs and Composite()

Post 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.
johnoyler

I see responses on others' posts...

Post by johnoyler »

Have I not supplied enough information? Not the correct information? Have I described my problem poorly?
johnoyler

Update:

Post 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?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply