I had a chance to draw a figure using pillow, but when I drew it with the default, it became a fluttering image. If you want to make it clean, you can export it in double size and specify antialiasing when resizing, but it's a bit annoying. I found a module that can be drawn beautifully from the beginning, so I will write it down.
Reference https://stackoverrun.com/ja/q/3880127 Reference https://aggdraw.readthedocs.io/en/latest/
It looks like this when drawing normally using pollow. Can you see that the horns are not processed and the jagi is out?
from PIL import Image, ImageDraw
image = Image.new('RGB', (300, 300), (255, 255, 255))
draw = ImageDraw.Draw(image)
draw.line((150, 50, 250, 250, 50, 250, 150, 50), fill=(0, 0, 0), width=20)
draw.line((10, 140, 290, 160), fill=(0, 0, 0), width=20)
image.save('test1.png', quality=100)
For the time being, rounding of corners is implemented in the new version of pillow. Just add * joint = "curve" * to the argument.
from PIL import Image, ImageDraw
image = Image.new('RGB', (300, 300), (255, 255, 255))
draw = ImageDraw.Draw(image)
draw.line((150, 50, 250, 250, 50, 250, 150, 50), fill=(0, 0, 0), width=20, joint="curve")
draw.line((10, 140, 290, 160), fill=(0, 0, 0), width=20)
image.save('test2.png', quality=100)
This will round the corners. The beginning and end of writing are not processed, so if you're curious, trace the first side again.
from PIL import Image, ImageDraw
image = Image.new('RGB', (300, 300), (255, 255, 255))
draw = ImageDraw.Draw(image)
draw.line((150, 50, 250, 250, 50, 250, 150, 50, 250, 250), fill=(0, 0, 0), width=20, joint="curve")
draw.line((10, 140, 290, 160), fill=(0, 0, 0), width=20)
image.save('test3.png', quality=100)
Installation was normal with pip
pip install aggdraw
With aggdraw, you can draw as it is on the Image created by pillow. It's like defining a pen and writing with it. Can you see that the jagi is gone because it does antialiasing and alpha synthesis on its own?
from PIL import Image
import aggdraw
image = Image.new('RGB', (300, 300), (255, 255, 255))
draw = aggdraw.Draw(image)
pen = aggdraw.Pen((0, 0, 0), 20)
draw.line((150, 50, 250, 250, 50, 250, 150, 50, 250, 250), pen)
draw.line((10, 140, 290, 160), pen)
draw.flush()
image.save('test4.png', quality=100)
There is also a brush (fill)
from PIL import Image
import aggdraw
image = Image.new('RGBA', (300, 300), (255, 255, 255, 255))
draw = aggdraw.Draw(image)
brush = aggdraw.Brush((0, 0, 0), 255)
draw.line((150, 50, 250, 250, 50, 250, 150, 50, 250, 250), brush)
draw.flush()
image.save('test5.png', quality=100)