pythonpython-imaging-librarythumbnails

To improve image quality of made circular thumbnails


How do I generate circular thumbnails with PIL? shows a way how to make circular thumbnails.

Following the sample and I am using a picture here, and here's what's generated.

enter image description here

The generated picture quality doesn't look very good, I want to improve it, so change the last line a bit:

from PIL import Image, ImageOps

mask = Image.open('mask.png').convert('L')
im = Image.open('image.png')

output = ImageOps.fit(im, mask.size, centering=(0.5, 0.5))
output.putalpha(mask)

output.save('output.png', dpi=(800,800))

But seems the picture quality is not improved.

What's the way to improve the picture quality after circled?

image with solution in the answer image with solution in the answer


Solution

  • Try using a different downsampling filter, by adding, for example, method=Image.LANCZOS to the .fit call.