Page 1 of 1

Lay one image on top of another with transparency?

Posted: 2007-01-26T11:46:55-07:00
by jenn5175
I know this is simple but I can't find any sample code and am getting frusterated.

I have 2 images. IMAGE1 is a JPG that is a photo. IMAGE2 is a JPG or GIF (whichever is easier) that is the same size and IMAGE1 and has, say, a logo in the bottom right corner and a border strip along the bottom with tagline or something - everything else is set to an RGB value I want to be transparent.

I need to lay IMAGE2 on top of IMAGE1 but with all pixels that are not the logo/tagline set to transparent. For example, IMAGE2 might be all limegreen except for the logo. I need to know how to make that limegreen color (or whatever RGB value I determine to be the "transparent color") transperent and then lay IMAGE2 directly on top of IMAGE1.

I have found a few workarounds with going pixel by pixel and such, but I will be doing this to thousands of photos at a time and I am thinking there is a function that does exactly what I need in an efficient manner. I just cannot figure out which one it is!

Ideas?
Jenn

Posted: 2007-01-27T02:58:42-07:00
by aditan22
If I may answer your question...

To make the image transparent, use this function: MagickPaintTransparentImage

and to merge both image, use:
MagickCompositeImage with MW_OverlayCompositeOp operator.

Hope this help you.

And... CMIIW or if there's other more efficient way... we're all learning here, right? except of course the imagemagick creators ;)

Posted: 2007-02-01T14:45:47-07:00
by monsters
Yeah, frustrating.

Basically your trying to do a watermark, check my sample code here
http://bigmojo.net/monsters/?p=6

I have it on this site somewhere, but you know, gotta pimp.