Fundamentals 9 min read

Master Pillow: 6 Essential Modules for Powerful Image Manipulation in Python

This tutorial introduces Pillow, the dominant Python imaging library, and walks through its six core modules—Image, ImageDraw, ImageEnhance, ImageFont, ImageGrab, and ImageFilter—showing how to load, edit, draw, enhance, capture, and filter images with practical code examples.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Master Pillow: 6 Essential Modules for Powerful Image Manipulation in Python

Introduction

Pillow is a powerful Python imaging library that succeeded PIL and now dominates image handling tasks.

Six Core Modules

Image – loading, saving, inspecting image format, mode, size, and basic operations such as verify, show, and save.

ImageDraw – drawing points, lines, arcs, ellipses, chords, pieslices, polygons, rectangles, and adding text or watermarks.

ImageEnhance – adjusting color balance, contrast, brightness, and sharpness.

ImageFont – loading TrueType fonts and rendering text onto images.

ImageGrab – capturing screenshots or specific screen regions.

ImageFilter – applying filters such as Gaussian blur, blur, edge enhance, find edges, emboss, contour, sharpen, smooth, and detail.

Code Samples

from PIL import Image
from io import BytesIO
# read an image
im = Image.open('2.jpg')
b = BytesIO()
im.save(b, 'JPEG')
data = b.getvalue()
print(data)  # binary data
print('Format:', im.format)
print('Mode:', im.mode)
print('Size:', im.size)
print('Info:', im.info)
im.verify()
im.show()
im.save('4.jpg', 'JPEG')

# ImageDraw example
from PIL import Image, ImageDraw
im = Image.open('2.jpg')
draw = ImageDraw.Draw(im)
draw.point([100, 200], fill='blue')
draw.line([100, 100, 600, 100], fill='green')
# ... more drawing commands ...

# ImageEnhance example
from PIL import ImageEnhance
im1 = Image.open('4.jpg')
enhancer = ImageEnhance.Contrast(im1)
im2 = enhancer.enhance(3.4)
im2.show()

# ImageFont example
from PIL import ImageFont, ImageDraw
font = ImageFont.truetype(r'C:\Windows\Fonts\simsun.ttc', size=40)
ImageDraw.Draw(im).text((50, 60), 'Hello World', fill='red', font=font)

# ImageGrab example
from PIL import ImageGrab
im1 = ImageGrab.grab((0, 0, 800, 200))
im1.show()

# ImageFilter example
from PIL import ImageFilter
im = Image.open('4.jpg')
im_blur = im.filter(ImageFilter.GaussianBlur)
im_blur.show()
# ... other filters ...

These snippets demonstrate creating new images, blending, point operations, cropping, pasting, channel splitting/merging, resizing, flipping, pixel access, thumbnail generation, rotation, mode conversion, drawing shapes, adding text, screen capture, and applying various filters.

With Pillow you can easily perform screenshot capture, watermarking, and even generate ASCII‑style images.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonpillowPIL
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.