TIMEX
TIMEX

Reputation: 271724

Python Image Library produces a crappy quality jpeg when I resize a picture

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

Upvotes: 4

Views: 4188

Answers (2)

Dinu Duke
Dinu Duke

Reputation: 185

Hope this might help someone:

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

Upvotes: 2

Jonathan Feinberg
Jonathan Feinberg

Reputation: 45324

Documentation sayyyyys:

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

Upvotes: 13

Related Questions