I use the Python Image Library (PIL) to resize an image and create a thumbnail. Why is it that my code produces an image that is so crappy and low-quality? Can someone tell me how to modify the code so that it's the highest quality JPEG?
def create_thumbnail(buffer, width=100, height=100):
im = Image.open(StringIO(buffer))
if im.mode not in ('L', 'RGB', 'RGBA'):
im = im.convert('RGB')
im.thumbnail((width, height), Image.ANTIALIAS)
thumbnail_file = StringIO()
im.save(thumbnail_file, 'JPEG')
thumbnail_file.seek(0)
return thumbnail_file
Documentation sayyyyys:
im.save(thumbnail_file, 'JPEG', quality=90)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With