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

encoding, file, image, python, python-imaging-library

Solution

Documentation sayyyyys:

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

Problem

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 ```

Original source

Related problems