[Image-SIG] Re: New to PIL and struggling...

Fredrik Lundh fredrik at pythonware.com
Thu Apr 21 19:49:10 CEST 2005

"charlie clark" wrote:

> I would like to be able to mark areas on a map with round points. I 
> already have the round points as a separate graphic with a transparent 
> background. When I use Image.paste(im, (10, 10)) the paste works but the 
> background of the pasted image is white rather than transparent. I think 
> that I should be doing something with a mask but I don't quite understand 
> how this works. Thanks for any tips.

to do a transparent paste, you need to pass in the mask (or matte) as the
third argument.

if you're pasting RGBA data into an RGB image, you can simply pass in the
overlay itself as the third argument:

    image.paste(im, (10, 10), im)

if you're using P images, you have to create a mask first.  something like this
might work:

    lut = [1] * 256
    lut[im.info["transparency"]] = 0
    mask = im.point(lut, "1")
    image.paste(im, (10, 10), mask)


More information about the Image-SIG mailing list