2

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? Thank you.

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

Mark K
  • 8,767
  • 14
  • 58
  • 118

1 Answers1

2

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

Ture Pålsson
  • 6,088
  • 2
  • 12
  • 15
  • thank you for the help! "output = ImageOps.fit(im, mask.size, centering=(0.8, 0.8), method = Image.LANCZOS)" works! – Mark K Feb 28 '20 at 08:04