Drawing semi-transparent polygons in PIL

image-processing, python

Solution

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

Edit: This works.

from PIL import Image
from PIL 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://effbot.org/imagingbook/image.htm#image-paste-method

Problem

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

Original source