If you followed a link here looking for the Python Imaging Library, this page is the short version of what happened and what to install instead.
Pillow, import PIL. That is not a typo, and it trips up nearly everybody the first time.python -m pip install Pillow
from PIL import Image
im = Image.open("photo.jpg")
print(im.format, im.size, im.mode)
im.thumbnail((200, 200))
im.save("thumb.png")
The Python Imaging Library was written by Fredrik Lundh and released through PythonWare. The last release was 1.1.7 in 2011. It was never ported to Python 3.
Pillow began in 2010 as a fork to make PIL installable with modern packaging, and became the maintained continuation of the project. It keeps the same import name, so from PIL import Image works in both. That choice is why twenty year old tutorials still look almost right, and also why so much old code fails in confusing ways rather than obviously.
Three kinds of change account for nearly every failure.
Old code did import Image. That has not worked since PIL 1.1.6, and needs to be from PIL import Image.
Pillow 9.1 grouped the loose constants into enums, and Pillow 10 removed the old names. Image.ANTIALIAS is the one everybody hits.
| Old name | Use this now |
|---|---|
Image.ANTIALIAS | Image.Resampling.LANCZOS |
Image.CUBIC | Image.Resampling.BICUBIC |
Image.LINEAR | Image.Resampling.BILINEAR |
Image.FLIP_LEFT_RIGHT | Image.Transpose.FLIP_LEFT_RIGHT |
Image.ROTATE_90 | Image.Transpose.ROTATE_90 |
Image.AFFINE | Image.Transform.AFFINE |
Image.ADAPTIVE | Image.Palette.ADAPTIVE |
Image.FLOYDSTEINBERG | Image.Dither.FLOYDSTEINBERG |
| Old call | Use this now |
|---|---|
im.tostring() | im.tobytes() |
Image.fromstring() | Image.frombytes() |
draw.textsize(text, font) | draw.textbbox((0, 0), text, font=font) |
font.getsize(text) | font.getbbox(text) or font.getlength(text) |
im.offset(x, y) | ImageChops.offset(im, x, y) |
PIL.VERSION | PIL.__version__ |
The converter tool applies all of this to a block of code and tells you what it changed.
Most of the library is the same. Image.open, save, crop, paste, convert, split, merge, the band and mode system, the coordinate system with the origin at the top left, and the lazy loading behaviour all work as they always did. A PIL era book is still a reasonable way to learn the model, as long as you translate the names above as you read.