How to generate a rounded image in Python.
Basically, I make the original image square and mask it with a circle, but if I use PIL (Pillow) Image, ImageDraw, etc., antialiasing does not work and I can only get through dirty.
With PIL (Pillow), it seems that only resize and thumbnail can set antialiasing and filters. stackoverflow
The solution is as follows.
from PIL import Image, ImageOps
mask = Image.open("Mask image path")
org = Image.open("Original image path")
sq = ImageOps.fit(sq, (400, 400), method = Image.LANCZOS)
sq.putalpha(mask.convert("L"))
sq.save("Path to save the image cut out in a circle")
Referenced page. stackoverflow
You can also use image libraries such as Cairo and aggdraw. However, I didn't use it because it doesn't seem to be maintained. Quora
Recommended Posts