How to thumbnail with Python and Pillow Python 03.01.2016

Install pillow

pip install Pillow

Snippet of code

from PIL import Image

SIZE = (315, 320)

im =
im.thumbnail(SIZE, Image.ANTIALIAS), 'JPEG', quality=80)

# get file size in bytes
import os

There are three different function to resize image

  • Image.resize changes the aspect ratio of the image.
  • Image.thumbnail keeps the aspect ratio of the image and scales it to the defined area.
  • keeps the aspect ratio and crops the image to the size of the defined area.