Python image library creates crappy jpeg quality when resizing image

I use the Python Image Library (PIL) to resize the image and create a thumbnail. Why is my code creating an image so crappy and substandard? Can someone tell me how to change the code so that it is 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 
+4
source share
2 answers

Documentation sayyyyys :

 im.save(thumbnail_file, 'JPEG', quality=90) 
+13
source

Hope this can help someone:

 from PIL import Image image = Image.open("2.jpg") image.thumbnail((256, 256), Image.ANTIALIAS) image.save("11.jpg", quality=100) 
+1
source

All Articles