[Image-SIG] pasting onto transparent background
Scott J. Cederberg
cederberg at maya.com
Fri Aug 12 21:22:49 CEST 2005
I'm trying to open a GIF (mode "P") with transparency, paste it onto a
(larger) transparent background, and write the resulting image as a
GIF, preserving transparency. In the resulting file, the parts of the
background that extend beyond the original image and the transparent
parts of the original image are correctly rendered as transparent.
However, the nontransparent parts of the original are solid black.
im = Image.open(file)
transparency = im.info['transparency']
transparent_layer = Image.new(im.mode, (x,y), transparency)
transparent_layer.paste(im, (x-im.size/2, y-im.size/2))
transparent_layer.save(outfile, "GIF", transparency=transparency)
I'm using Python v. 2.3.4, PIL v. 1.1.4, GifImagePlugin.py v. 0.8.
More information about the Image-SIG