Pillow Common Modules and Methods
Pillow provides rich functionality, including image opening, editing, saving, format conversion, etc.
This article will introduce Pillow's common modules and methods, and provide simple code examples.
Common Modules
| Module Name | Function Category | Core Functionality | Common Methods/Attributes | Typical Application Scenarios |
|---|---|---|---|---|
| Image | Core Module | Basic Image Operations | open(), save(), resize(), crop(), rotate(), convert() | Image loading/saving/resizing/format conversion |
| ImageDraw | Drawing Module | Vector graphics drawing | Draw(), line(), rectangle(), text(), ellipse() | Add watermarks/draw shapes/annotate images |
| ImageFont | Font Support | Text rendering | truetype(), load_default(), getsize() | Custom text styles/calculate text area |
| ImageFilter | Image Effects | Filter processing | BLUR, SHARPEN, EMBOSS, GaussianBlur() | Image blur/sharpening/artistic effects |
| ImageEnhance | Image Optimization | Quality enhancement | Brightness(), Contrast(), Color(), Sharpness() | Brightness/contrast/saturation adjustment |
| ImageOps | Advanced Operations | Automation processing | grayscale(), flip(), mirror(), invert() | Image inversion/mirror/forced grayscale |
| ImageChops | Channel Operations | Mathematical operations | add(), subtract(), multiply(), difference() | Image compositing/difference detection/mask processing |
| ImageColor | Color System | Color conversion | getrgb(), getcolor(), colormap | HEX/RGB/HSL color conversion |
| ImageGrab | Screen Capture | Screenshot functionality | grab(), grabclipboard() | Screenshot/clipboard image acquisition |
| ImageStat | Data Analysis | Pixel statistics | Stat(), extrema(), mean(), rms() | Image color analysis/brightness detection |
| ImagePalette | Palette | Indexed color management | new(), getcolor(), tobytes() | 8-bit color image processing/GIF optimization |
| ImagePath | Path Processing | Vector paths | Path(), getbbox(), compact() | Complex shape drawing (requires ImageDraw) |
| ImageSequence | Animated Images | Frame processing | Iterator(), all_frames() | GIF animation decomposition/multi-frame TIFF processing |
| ImageMorph | Morphology | Image morphing | MorphOp(), apply(), get_on_pixels() | Pattern dilation/erosion/structural analysis |
| ImageShow | Image Preview | Quick display | show(), register_viewer() | Quickly view images during debugging |
| ImageTk | GUI Integration | Tkinter support | PhotoImage(), BitmapImage() | Display images in Tkinter interface |
| ImageQt | GUI Integration | Qt support | ImageQt(), toqimage() | PyQt/PySide image display |
| ExifTags | Metadata | EXIF reading | TAGS, GPSTAGS | Read camera parameters/GPS information |
| PSDraw | Print Output | PostScript | PSDraw(), begin_document() | Generate vector files for printing |
| TiffTags | Metadata | TIFF Tags | TIFFTAGS | Process TIFF format metadata |
Module Workflow

Advanced processing combinations:
- Effects creation: ImageFilter + ImageEnhance
- Image analysis: ImageStat + ImageChops
- GUI development: ImageTk/ImageQt + ImageDraw
Professional domain support:
- Scientific images: TIFFTags + ImageSequence
- Print publishing: PSDraw + ImageColor
- Computer vision: ImageMorph + ImageOps
Common Methods
PIL.ImageModule Common Methods
| Method | Description | Example |
|---|---|---|
Image.open() |
Open image file | img = Image.open("example.jpg") |
Image.save() |
Save image file | img.save("output.png") |
Image.show() |
Display image | img.show() |
Image.resize() |
Resize image | new_img = img.resize((200, 200)) |
Image.rotate() |
Rotate image | rotated_img = img.rotate(45) |
Image.crop() |
Crop image | cropped_img = img.crop((50, 50, 200, 200)) |
Example code:
Example
from PIL import Image
# Open image
img = Image.open("example.jpg")
# Resize and save
resized_img = img.resize((300, 300))
resized_img.save("resized_example.jpg")
# Rotate 90 degrees and display
rotated_img = img.rotate(90)
rotated_img.show()
# Open image
img = Image.open("example.jpg")
# Resize and save
resized_img = img.resize((300, 300))
resized_img.save("resized_example.jpg")
# Rotate 90 degrees and display
rotated_img = img.rotate(90)
rotated_img.show()
PIL.ImageDrawModule Common Methods
| Method | Description | Example |
|---|---|---|
ImageDraw.Draw() |
Create drawing object | draw = ImageDraw.Draw(img) |
draw.line() |
Draw line | draw.line([(0, 0), (100, 100)], fill="red", width=2) |
draw.rectangle() |
Draw rectangle | draw.rectangle([(50, 50), (150, 150)], outline="blue", width=3) |
draw.text() |
Draw text | draw.text((10, 10), "Hello", fill="black") |
Example code:
Example
from PIL import Image, ImageDraw
# Create a blank image
img = Image.new("RGB", (300, 300), "white")
draw = ImageDraw.Draw(img)
# Draw a red line
draw.line([(0, 0), (300, 300)], fill="red", width=2)
# Draw a blue rectangle
draw.rectangle([(50, 50), (250, 250)], outline="blue", width=3)
# Add text
draw.text((100, 100), "Hello Pillow!", fill="black")
# Save image
img.save("draw_example.png")
img.show()
# Create a blank image
img = Image.new("RGB", (300, 300), "white")
draw = ImageDraw.Draw(img)
# Draw a red line
draw.line([(0, 0), (300, 300)], fill="red", width=2)
# Draw a blue rectangle
draw.rectangle([(50, 50), (250, 250)], outline="blue", width=3)
# Add text
draw.text((100, 100), "Hello Pillow!", fill="black")
# Save image
img.save("draw_example.png")
img.show()
PIL.ImageFilterModule Common Methods
| Method | Description | Example |
|---|---|---|
ImageFilter.BLUR |
Blur filter | img.filter(ImageFilter.BLUR) |
ImageFilter.CONTOUR |
Contour filter | img.filter(ImageFilter.CONTOUR) |
ImageFilter.SHARPEN |
Sharpen filter | img.filter(ImageFilter.SHARPEN) |
Example code:
Example
from PIL import Image, ImageFilter
# Open image
img = Image.open("example.jpg")
# Apply blur filter
blurred_img = img.filter(ImageFilter.BLUR)
blurred_img.save("blurred_example.jpg")
# Apply sharpen filter
sharpened_img = img.filter(ImageFilter.SHARPEN)
sharpened_img.show()
# Open image
img = Image.open("example.jpg")
# Apply blur filter
blurred_img = img.filter(ImageFilter.BLUR)
blurred_img.save("blurred_example.jpg")
# Apply sharpen filter
sharpened_img = img.filter(ImageFilter.SHARPEN)
sharpened_img.show()