Is there any way to make nice round corners with python? Currently PIL and GD2 are used in my project. Both of them have an arc()
method, that allows you to draw a quater-circle, but the quater-circle is not antialiased, so the image looks crispy.
Is there any neat way to make antialiased/smooth round corners?
What I usually do is use an image as a mask, like this one for example:
border.png
border = Image.open('border.png')
source = border.convert('RGB')
img.paste(source, mask=border)
The mask can be resized to fit the dimensions you want. Just make sure to use the Image.ANTIALIAS method.
You can refer to the tutorial I wrote a while ago for more details (shameless plug)
If you want more control over the size and the radius then you need to use arc or pieslice. I don't know about you but this rounded rectangle I created with PIL looks smooth enough to me:
Here is the code I used to draw it
Maybe you should check phatch: http://photobatch.wikidot.com/tutorials It is written in Python and PIL and can apply round corners to photos.
Here is a link to the code used to apply round corners: http://bazaar.launchpad.net/~stani/phatch/trunk/annotate/head:/phatch/actions/round.py
That also looks smooth enough to me.