Python Pillow - Function Reference



Python Pillow, a powerful image processing library, offers a wide range of modules and functionalities to perform various image-related tasks. From basic operations like channel manipulations to advanced features such as generating graphics and evaluating mathematical expressions on images. Below, you'll find an overview of the modules offered by Pillow along with details about their methods.

ImageChops (“Channel Operations”) Module

The ImageChops module, referred to as "channel operations" or "chops" provides a range of operations that can be performed on images, primarily to perform mathematical image operations such as enhancing special effects, creating composite images, algorithmic painting, and more. These operations are useful for image enhancement, blending, and creating effects.

It's important to note that, currently, most channel operations are only available for 8-bit images, such as "L" and "RGB."

Functions

Channel operations typically accept one or two image inputs and produce a new image as output. Unless specified otherwise, the result of a channel operation is always clipped within the 0 to MAX range. For the supported modes in this module, MAX is set to 255.

The following are the methods available in this Module −

Sr.No. Methods with Description
1

ImageChops.add()

Adds two images, and divides the result by a specified scale, and then adds an offset.

2

ImageChops.subtract()

Subtracts one image from another, and divides the result by a specified scale, and then adds an offset.

3

ImageChops.add_modulo()

Add two images without clipping the result.

4

ImageChops.subtract_modulo()

Subtract two images without clipping the result.

5

ImageChops.composite()

Composites two images by blending two images using a mask.

6

ImageChops.duplicate()

Returns a copy of the image.

7

ImageChops.darker()

Compares two images and returns the darker pixel value for each pixel.

8

ImageChops.constant()

Creates a new image by filling the channel of an image with a given grey level.

9

ImageChops.difference()

Computes the absolute difference between two images.

10

ImageChops.invert()

Inverts the pixel values of an image.

11

ImageChops.lighter()

Compares two images and returns the lighter pixel value for each pixel.

12

ImageChops.logical_and()

It performs the logical AND between two images.

13

ImageChops.logical_or()

It performs the logical OR between two images.

14

ImageChops.logical_xor()

It performs the logical XOR between two images.

15

ImageChops.multiply()

Multiplies two images together.

16

ImageChops.soft_light()

Superimposes two images on top of each other using the Soft Light algorithm.

17

ImageChops.hard_light()

Superimpose two images on top of each other using the Hard Light algorithm.

18

ImageChops.overlay()

Applies an overlay blending mode between two images.

19

ImageChops.offset()

Shifts the image by a given offset.

20

ImageChops.screen()

Superimposes two inverted images on top of each other using the screen blending mode.

ImageOps Module

The ImageOps module provides a set of ready-made operations for image processing. The following are the list of methods available in this Module. Let's explore and understand the basic fuctionality of each method.

Sr.No. Methods with Description
1

ImageOps.autocontrast()

Enhances the contrast of an image automatically.

2

ImageOps.colorize()

Colorizes a grayscale image.

3

ImageOps.scale()

Scales the image by a given factor.

4

ImageOps.equalize()

Equalizes the histogram of an image.

5

ImageOps.grayscale()

Converts an image to grayscale.

6

ImageOps.posterize()

Reduces the number of bits for each color channel.

7

ImageOps.solarize()

Inverts all pixel values above a threshold.

ImageDraw Module

The ImageDraw module provides simple 2D graphics support for creating new images, adding shapes, and drawing text. It is commonly used for generating graphics on the fly and for annotating images.

The following are the list of methods available in this Module. Let's explore and understand the basic fuctionality of each method −

Sr.No. Methods with Description
1

ImageDraw.arc()

Draws an arc inside a specified bounding box.

2

ImageDraw.chord()

Draws a chord (a segment of a circle) inside a bounding box.

3

ImageDraw.pieslice()

Draws a filled pie slice inside a bounding box.

4

ImageDraw.point()

Draws points (single pixels) at specified coordinates on an image.

5

ImageDraw.regular_polygon()

Draws a regular polygon with a given bounding circle.

6

ImageDraw.rounded_rectangle()

Draws a rounded rectangle.

7

ImageDraw.multiline_text()

Draws multiline text at a specified position on an image.

ImageGrab Module

The ImageGrab module provides functions for capturing the contents of the screen or part of the screen to the PIL Image memory. It can be used to take screenshots or to capture images from the clipboard. Let's explore and understand the basic fuctionality of each functions available in this module −

Sr.No. Methods with Description
1

ImageGrab.grab()

Captures the snapshot of the screen.

2

ImageGrab.grabclipboard()

Captures a snapshot of the clipboard image.

ImageMath Module

The ImageMath module allows you to evaluate image expressions. And you can perform operations, such as arithmetic, bitwise, and logical operations, on images. Let's explore and understand the basic fuctionality of the method −

Sr.No. Methods with Description
1

ImageMath.eval()

Evaluates a mathematical expression on images.

Advertisements