Image Module
Anonymous contributor
Published Jun 7, 2024
Contribute to Docs
The Image
module in Pillow, a popular Python library for image processing, provides a comprehensive suite of tools for opening, creating, manipulating, and saving images in various formats. It allows users to perform a wide range of operations such as resizing, cropping, rotating, and flipping images. Additionally, the module supports converting images between different modes (e.g., RGB to grayscale) and accessing or modifying individual pixels, making it a powerful and versatile tool for handling image data in Python applications.
Syntax
from PIL import Image
This statement imports the Image
module from the Pillow library, which is a fork of the Python Imaging Library (PIL).
Image Module
- .alpha_composite()
- Merges two images by overlaying the foreground onto the background using their alpha (transparency) channels.
- .blend()
- Creates a new image by interpolating between two input images using a constant alpha value.
- .composite()
- Creates a composite image by blending two images using a transparency mask.
- .convert()
- Converts an image from one mode to another.
- .crop()
- Returns a given image cropped to a specified rectangular area.
- .effect_noise()
- Generates an image with Gaussian noise centered around 128.
- .eval()
- Applies a function to each pixel of an image, returning a new image with modified pixel values.
- .frombuffer()
- Creates an image memory from a bytes or buffer object containing raw pixel data.
- .frombytes()
- Creates an image from raw byte data using a specified mode, size, and optional decoder arguments.
- .getbands()
- Returns a tuple that contains the name of each band in the image.
- .getbbox()
- Returns the bounding box of the non-zero regions in the image.
- .getcolors()
- Returns colors and their frequencies in an image.
- .getdata()
- Returns pixel values of an image as a sequence, useful for inspection and processing.
- .getextrema()
- Returns the minimum and maximum pixel values for each band in an image.
- .getpixel()
- Returns the pixel value at the specified coordinates.
- .histogram()
- Computes the histogram of an image.
- .merge()
- Merges set of single-band images into a new multi-band image.
- .open()
- Returns an image object from an image file.
- .paste()
- Pastes an image onto another image at a specified position.
- .point()
- Applies a function or lookup table to each pixel in an image.
- .putalpha()
- Modifies the alpha channel (transparency) of an image in the Pillow library.
- .putdata()
- Updates the pixel values of an image by setting the pixel data from a sequence or iterable, such as a list or tuple.
- .putpixel()
- Sets the color of a specific pixel in an image to a given value.
- .resize()
- Changes the size of an image to a specified size.
- .rotate()
- Rotates a given image anti-clockwise around its center by the specified number of degrees.
- .save()
- Saves an image to a specified file.
- .show()
- Displays an image using the default image viewer on the system.
- .transpose()
- Flips or rotates an image according to the specified operation.
- fromarray()
- Creates an image from a specified array.
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:Pillow on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours