views:

40

answers:

1

How do you draw semi-transparent polygons using the Python Imaging Library?

A: 

Can you draw the polygon on a separate RGBA image then use the Image.paste(image, box, mask) method?

Edit: This works.

>>> import Image
>>> import ImageDraw
>>> back = Image.new('RGBA', (512,512), (255,0,0,0))
>>> poly = Image.new('RGBA', (512,512))
>>> pdraw = ImageDraw.Draw(poly)
>>> pdraw.polygon([(128,128),(384,384),(128,384),(384,128)],
...               fill=(255,255,255,127),outline=(255,255,255,255))
>>> back.paste(poly,mask=poly)
>>> back.show()

http://www.pythonware.com/library/pil/handbook/image.htm#image-paste-method

Nick T