[Image-SIG] A Pil Doubt
Douglas Bagnall
douglas@paradise.net.nz
Wed, 17 Jan 2001 16:17:14 +1300
Carlos Moreira asks:
> Hi,
>
> I need some help. How I can, in Python Imaging Library, create a
> transparent GIF?
tsk,tsk.. it's illegal you know.
I managed it by using a modifed version of the _save_netpbm function in
/PIL/GifImagePlugin.py, which uses the external but common and free
netpbm library.
I only wanted white as a transparent colour, so I hard-coded in the
'#FFFFFF'. Everything except " -transparent '#FFFFFF' " is straight out
of PIL.
douglas
def _save_netpbm_trans(im, fp, filename):
import os
file = im._dump()
if im.mode != "RGB":
os.system("ppmtogif -transparent '#FFFFFF' %s >%s" % (file, filename))
else:
os.system("ppmquant 256 %s | ppmtogif -transparent '#FFFFFF' >%s" % (file, filename))
try: os.unlink(file)
except: pass
Image.register_save("GIF", _save_netpbm_trans) #sets PIL to use proper GIF compression
------- End of forwarded message -------