[Image-SIG] pasting onto transparent background

Scott J. Cederberg cederberg at maya.com
Fri Aug 12 21:22:49 CEST 2005


Hi,

   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.

   Code:

   im = Image.open(file)
   transparency = im.info['transparency']
   transparent_layer = Image.new(im.mode, (x,y), transparency)
   transparent_layer.paste(im, (x-im.size[0]/2, y-im.size[0]/2))
   transparent_layer.save(outfile, "GIF", transparency=transparency)

Any thoughts?

I'm using Python v. 2.3.4, PIL v. 1.1.4, GifImagePlugin.py v. 0.8.

                                                           Scott


More information about the Image-SIG mailing list