I have been hitting my head against the wall for a while with this, so maybe someone out there can help.
I\'m using PIL to open a PNG with transparent background and
I think what you want to use is the paste mask argument.
see the docs, (scroll down to paste
)
from PIL import Image
img = Image.open(basefile)
layer = Image.open(layerfile) # this file is the transparent one
print layer.mode # RGBA
img.paste(layer, (xoff, yoff), mask=layer)
# the transparancy layer will be used as the mask
img.save(outfile)