Pillow
Pillow is the maintained fork of PIL, the Python Imaging Library. Image.open reads a file and detects its format from the contents, and save writes it back out, choosing the format from the file extension. Between the two, modules such as ImageDraw, ImageFilter, and ImageOps draw, filter, resize, crop, and convert colors. Reading covers many more formats than writing, which sticks to the common interchange formats.
- Downloads / mo
- 436.5M
- Stars
- 14.0K
- Last release
- 13.0.0, Oct 2026
- License
- MIT-CMU
Strengths
- Everyday image tasks. Thumbnails, resizing, format conversion, drawing, and metadata in one package.
- Text, EXIF, and color profiles. ImageDraw renders text, and Pillow reads EXIF metadata and converts ICC color profiles.
- Prebuilt wheels. pip installs prebuilt wheels, with no separate image program to install.
Limitations
- Slow on large images. A large blur took 15 times as long as OpenCV's.
- No video or camera input. Use OpenCV or imageio for video.
Quickstart
from PIL import Image with Image.open("hopper.jpg") as im: print(im.getbands()) # Returns ('R', 'G', 'B')
Pillow examples
Resizes an uploaded image to a fixed size, applying EXIF rotation and saving it as WebP with Pillow.
def resize_image( image: File, *, size: tuple[int, int], cover=True, keep_format=False, ) -> ImageFile: # ... with Image.open(image) as img: try: # Take any orientation EXIF data, apply it, and strip the # orientation data from the new image. img = ImageOps.exif_transpose(img) # ... if cover: resized_image = ImageOps.fit(img, size, method=Image.Resampling.BILINEAR) else: resized_image = img.copy() resized_image.thumbnail(size, resample=Image.Resampling.BILINEAR) new_image_bytes = io.BytesIO() if keep_format: resized_image.save(new_image_bytes, format=img.format) file = ImageFile(new_image_bytes) else: resized_image.save(new_image_bytes, format="webp", save_all=True) file = ImageFile(new_image_bytes, name="image.webp") file.image = resized_image return file
Makes a thumbnail with Pillow, rotating it to match the EXIF orientation and cropping it to fit.
def fancy_pillow(self, im: "Image.Image", fmt: str, vn: VFS) -> "Image.Image": # exif_transpose is expensive (loads full image + unconditional copy) res = self.getres(vn, fmt) r = max(*res) * 2 im.thumbnail((r, r), resample=Image.LANCZOS) try: k = next(k for k, v in ExifTags.TAGS.items() if v == "Orientation") exif = im.getexif() rot = int(exif[k]) del exif[k] except: rot = 1 rots = {8: Image.ROTATE_90, 3: Image.ROTATE_180, 6: Image.ROTATE_270} if rot in rots: im = im.transpose(rots[rot]) if "f" in fmt: im.thumbnail(res, resample=Image.LANCZOS) else: iw, ih = im.size dw, dh = res res = (min(iw, dw), min(ih, dh)) im = ImageOps.fit(im, res, method=Image.LANCZOS) return im