Learn Pillow

Python's friendly imaging library for opening, editing and saving images

15 lessons · 3 hours · 4 levels · covers Pillow 12.x

Pillow is the maintained fork of PIL, the Python Imaging Library. It reads and writes dozens of image formats and handles everyday edits: resizing, cropping, rotating, drawing text, filters, colour conversion and metadata. Web backends, scripts and ML data pipelines use it whenever images need to be loaded or produced.

Before you start

Pillow builds on these; the tree links to the exact lessons you need.

How deep do you want to go?

1. EssentialsRead and write simple code, do the everyday basics4 lessons · 38 min in total
2. PracticalUse it productively at work, with the usual idioms9 lessons · 2 hours in total
3. AdvancedThe less common features, performance and trade-offs12 lessons · 2 hours in total
4. ExpertInternals and the edge cases experts know15 lessons · 3 hours in total

The Pillow tree

PillowOpening images: the Image objectOpening images: theImage objectModes and convert()Modes and convert()Resize, thumbnail and cropResize, thumbnailand cropSaving: formats, quality and optionsSaving: formats,quality and optionsRotate, transpose and EXIF orientationRotate, transposeand EXIF orientationImageDraw and fontsImageDraw and fontsFilters, enhancement and ImageOpsFilters, enhancementand ImageOpsPasting, masks and alpha compositingPasting, masks andalpha compositingPillow and NumPy arraysPillow and NumPyarraysModules and importsModules and importsReading and writing filesReading and writingfilesDictionariesDictionariesIterators and generatorsIterators andgeneratorsContext managers and withContext managersand withExceptions in depthExceptions in depthClasses and instancesClasses andinstances
Essentials and Practical shown (9 of 15 lessons); the full list is below. Click a lesson to read it.

All 15 lessons, in order

Opening and saving

  1. Opening images: the Image object · Essentials · 8 min

    Open a file with Image.open and inspect its format, size and mode; create new images with Image.new.

  2. Modes and convert() · Essentials · 10 min

    Understand RGB, RGBA, L, 1, P, CMYK and I;16 modes and convert between them correctly.

  3. Resize, thumbnail and crop · Essentials · 10 min

    Scale images with resize and the right resampling filter, make bounded thumbnails, and crop with boxes.

  4. Saving: formats, quality and options · Essentials · 10 min

    Save as PNG, JPEG, WebP and more, controlling quality, optimisation and progressive encoding.

Everyday editing

  1. Rotate, transpose and EXIF orientation · Practical · 10 min

    Rotate and flip images correctly, and apply the camera's EXIF orientation with ImageOps.exif_transpose.

  2. Filters, enhancement and ImageOps · Practical · 10 min

    Blur, sharpen and find edges with ImageFilter, adjust brightness and contrast with ImageEnhance, and use ImageOps helpers.

  3. Pillow and NumPy arrays · Practical · 10 min

    Convert between Image objects and NumPy arrays with np.asarray and Image.fromarray, minding shape, dtype and mode.

Drawing and compositing

  1. ImageDraw and fonts · Practical · 12 min

    Draw shapes and text with ImageDraw, load TrueType fonts and measure text with textbbox.

  2. Pasting, masks and alpha compositing · Practical · 12 min

    Combine images with paste and masks, alpha_composite for proper transparency, and blend for cross-fades.

Metadata and multi-frame images

  1. EXIF, ICC profiles and image info · Advanced · 12 min

    Read and write EXIF tags with getexif, find the info dictionary, and decide what metadata to keep or strip.

  2. Multi-frame images and animation · Advanced · 12 min

    Iterate frames of GIFs, animated WebP and multi-page TIFFs with seek and ImageSequence, and save animations.

  3. Large images: lazy loading, draft and reduce · Advanced · 10 min

    Handle huge images efficiently with lazy opening, JPEG draft mode, reduce, and closing files properly.

Production and internals

  1. Handling untrusted images safely · Expert · 12 min

    Defend upload endpoints against decompression bombs, format confusion, malformed files and metadata leaks.

  2. Format plugins and decoder internals · Expert · 15 min

    How Pillow identifies formats, decodes through tiles and C codecs, and how to feed incremental data or register a plugin.

  3. Colour management with ImageCms · Expert · 12 min

    Convert images between ICC colour profiles such as Display P3, Adobe RGB, sRGB and CMYK using ImageCms.