Thank you. That looks like a great function. Before I saw this however, I clunked together code from a few different sources to get a dynamically generating, smoothly anti-aliased image mask.
The only problem I have now, and it's a problem which I haven't been able to get around irrespective of the image mask, is that I can't get anything to display inside of a UI imageview except using the load_from_url() method.
Here is the code I am using in a manner which seems right to me. It runs with no errors, but the imageview remains empty.
import ui
import cStringIO
import urllib2
from PIL import Image, ImageOps, ImageDraw
url= "http://vignette2.wikia.nocookie.net/jamesbond/images/3/31/Vesper_Lynd_(Eva_Green)_-_Profile.jpg/revision/latest?cb=20130506215331"
v= ui.load_view('imageviewtest.pyui')
imageView1=v["imageview1"]
#load image from url and show it
file=cStringIO.StringIO(urllib2.urlopen(url).read())
img = Image.open(file)
#begin mask creation
bigsize = (img.size[0] * 3, img.size[1] * 3)
mask = Image.new('L', bigsize, 0)
draw = ImageDraw.Draw(mask)
draw.ellipse((0, 0) + bigsize, fill=255)
mask = mask.resize(img.size, Image.ANTIALIAS)
img.putalpha(mask)
#show final masked image
img.show()
#change image to string form to be able to insert into a ui image view...hopefully
imgString = img.tostring()
imageView1.image = ui.Image.from_data(imgString)
v.present()