or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

color-management.mdcolor-utilities.mdcore-image.mddrawing.mdenhancement.mdfilters.mdfonts.mdimage-sequences.mdimage-statistics.mdindex.mdmath-operations.mdoperations.md
tile.json

tessl/pypi-pillow

Python Imaging Library (Fork) providing comprehensive image processing capabilities for reading, writing, and manipulating images across dozens of formats.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pillow@11.3.x

To install, run

npx @tessl/cli install tessl/pypi-pillow@11.3.0

index.mddocs/

Pillow (PIL)

Pillow is a comprehensive Python imaging library that serves as the friendly fork of the Python Imaging Library (PIL), providing extensive image processing capabilities for Python applications. It offers robust file format support for reading, writing, and manipulating images across dozens of formats including JPEG, PNG, TIFF, GIF, BMP, and many specialized formats, with efficient internal representation optimized for performance.

Package Information

  • Package Name: pillow
  • Language: Python
  • Installation: pip install pillow

Core Imports

from PIL import Image

Common for working with specific functionality:

from PIL import Image, ImageDraw, ImageFilter, ImageFont, ImageOps
from PIL import ImageChops, ImageColor, ImageStat, ImageSequence

For specialized tasks:

from PIL import ImageEnhance, ImageCms, ExifTags, TiffTags

Basic Usage

from PIL import Image

# Open an image
image = Image.open("example.jpg")

# Get basic info
print(f"Size: {image.size}")
print(f"Mode: {image.mode}")
print(f"Format: {image.format}")

# Basic operations
resized = image.resize((800, 600))
rotated = image.rotate(90)
converted = image.convert("L")  # Convert to grayscale

# Save the image
resized.save("resized_example.jpg")

# Create a new image
new_image = Image.new("RGB", (400, 300), color="red")
new_image.save("red_rectangle.png")

Architecture

Pillow's architecture centers around the Image class as the primary interface for image manipulation:

  • Image Class: Core object representing image data with methods for manipulation, conversion, and I/O operations
  • Format Plugins: Modular system supporting 40+ image formats through dedicated plugin modules
  • Drawing Subsystem: Vector graphics capabilities through ImageDraw for creating and annotating images
  • Filter System: Extensible filtering framework for image enhancement and effects
  • Color Management: Comprehensive color space handling and ICC profile support
  • Font Rendering: TrueType/OpenType font support for text rendering on images

This design provides maximum compatibility across image formats while maintaining performance through C extensions for critical operations.

Capabilities

Core Image Operations

Essential image manipulation functions including opening, creating, resizing, rotating, cropping, and format conversion. The Image class provides the foundation for all image operations.

def open(fp, mode="r", formats=None): ...
def new(mode, size, color=0): ...

class Image:
    def resize(self, size, resample=None, box=None, reducing_gap=None): ...
    def rotate(self, angle, resample=0, expand=0, center=None, translate=None, fillcolor=None): ...
    def crop(self, box=None): ...
    def convert(self, mode=None, matrix=None, dither=None, palette=0, colors=256): ...
    def save(self, fp, format=None, **params): ...

Core Image Operations

Drawing and Graphics

Vector graphics capabilities for drawing shapes, text, and other graphical elements on images. Supports various drawing primitives and text rendering with font support.

def Draw(im, mode=None): ...

class ImageDraw:
    def line(self, xy, fill=None, width=0, joint=None): ...
    def rectangle(self, xy, fill=None, outline=None, width=1): ...
    def ellipse(self, xy, fill=None, outline=None, width=1): ...
    def polygon(self, xy, fill=None, outline=None, width=1): ...
    def text(self, xy, text, fill=None, font=None, anchor=None, spacing=4, align="left", direction=None, features=None, language=None, stroke_width=0, stroke_fill=None, embedded_color=False): ...

Drawing and Graphics

Image Filters and Enhancement

Comprehensive filtering system for image enhancement, blur effects, edge detection, and artistic effects. Includes both built-in filters and custom filter creation capabilities.

class Filter: ...
class GaussianBlur(MultibandFilter): ...
class UnsharpMask(MultibandFilter): ...

# Built-in filter instances
BLUR: Filter
CONTOUR: Filter
DETAIL: Filter
EDGE_ENHANCE: Filter
SHARPEN: Filter

Image Filters

Font Handling and Text

TrueType and OpenType font support for rendering text on images with full typography control including size, spacing, alignment, and styling options.

def load_default(size=None): ...
def truetype(font=None, size=10, index=0, encoding="", layout_engine=None): ...

class FreeTypeFont:
    def getsize(self, text, direction=None, features=None, language=None, stroke_width=0): ...
    def getmask(self, text, mode="", direction=None, features=None, language=None, stroke_width=0, anchor=None, ink=0, start=None): ...

Font Handling

Image Operations and Transformations

Advanced image manipulation functions including automatic contrast adjustment, color space operations, geometric transformations, and specialized processing operations.

def autocontrast(image, cutoff=0, ignore=None, mask=None, preserve_tone=False): ...
def equalize(image, mask=None): ...
def fit(image, size, method=3, bleed=0.0, centering=(0.5, 0.5)): ...
def grayscale(image): ...
def invert(image): ...
def posterize(image, bits): ...
def solarize(image, threshold=128): ...

Image Operations

Color Management

Professional color management with ICC profile support, color space conversions, and rendering intent control for accurate color reproduction across devices and media.

def profileToProfile(im, inputProfile, outputProfile, renderingIntent=0, outputMode=None, inPlace=False, flags=0): ...
def buildTransform(inputProfile, outputProfile, inMode, outMode, renderingIntent=0, flags=0): ...
def createProfile(colorSpace, colorTemp=None): ...

class ImageCmsProfile: ...
class ImageCmsTransform: ...

Color Management

Image Enhancement

Systematic image quality improvement through brightness, contrast, color saturation, and sharpness adjustments with intuitive enhancement classes.

class Color:
    def enhance(self, factor): ...

class Contrast:
    def enhance(self, factor): ...

class Brightness:
    def enhance(self, factor): ...

class Sharpness:
    def enhance(self, factor): ...

Image Enhancement

Mathematical Operations

Pixel-level mathematical operations between images including blending, compositing, arithmetic operations, logical operations, and advanced blend modes for comprehensive image processing workflows.

def add(image1, image2, scale=1.0, offset=0): ...
def subtract(image1, image2, scale=1.0, offset=0): ...
def multiply(image1, image2): ...
def blend(image1, image2, alpha): ...
def composite(image1, image2, mask): ...
def difference(image1, image2): ...
def screen(image1, image2): ...
def overlay(image1, image2): ...
def logical_and(image1, image2): ...
def offset(image, xoffset, yoffset=None): ...

Mathematical Operations

Color Utilities

Comprehensive color conversion and name resolution utilities for handling CSS-style color strings, named colors, and conversion between different color formats and image modes.

def getrgb(color: str) -> tuple[int, int, int] | tuple[int, int, int, int]: ...
def getcolor(color: str, mode: str) -> int | tuple[int, ...]: ...

Color Utilities

Image Statistics

Statistical analysis capabilities for images providing detailed metrics about pixel distributions, central tendencies, and variability across image bands.

class Stat:
    def __init__(self, image_or_list, mask=None): ...
    @property
    def mean(self) -> list[float]: ...
    @property
    def median(self) -> list[int]: ...
    @property
    def extrema(self) -> list[tuple[int, int]]: ...
    @property
    def var(self) -> list[float]: ...
    @property
    def stddev(self) -> list[float]: ...

Image Statistics

Image Sequences

Animation and multi-frame image support for iterating through frames in animated GIFs, multi-page TIFFs, and other sequence-based image formats.

class Iterator:
    def __init__(self, im: Image.Image): ...
    def __getitem__(self, ix: int) -> Image.Image: ...
    def __iter__(self) -> Iterator: ...
    def __next__(self) -> Image.Image: ...

def all_frames(im, func=None) -> list[Image.Image]: ...

Image Sequences

Constants and Enums

Image Modes

  • "1" - 1-bit pixels, black and white, stored as 8 bits per pixel
  • "L" - 8-bit pixels, black and white
  • "P" - 8-bit pixels, mapped to any other mode using a color palette
  • "RGB" - 3x8-bit pixels, true color
  • "RGBA" - 4x8-bit pixels, true color with transparency mask
  • "CMYK" - 4x8-bit pixels, color separation
  • "YCbCr" - 3x8-bit pixels, color video format
  • "LAB" - 3x8-bit pixels, the Lab* color space
  • "HSV" - 3x8-bit pixels, Hue, Saturation, Value color space

Resampling Filters

class Resampling(IntEnum):
    NEAREST = 0
    BILINEAR = 1
    BICUBIC = 2
    LANCZOS = 3
    BOX = 4
    HAMMING = 5

Transform Types

class Transform(IntEnum):
    AFFINE = 0
    EXTENT = 1
    PERSPECTIVE = 2
    QUAD = 3
    MESH = 4

Transpose Operations

class Transpose(IntEnum):
    FLIP_LEFT_RIGHT = 0
    FLIP_TOP_BOTTOM = 1
    ROT_90 = 2
    ROT_180 = 3
    ROT_270 = 4
    TRANSPOSE = 5
    TRANSVERSE = 6