1. Products
  2.   Image
  3.   Python
  4.   Pillow
 
  

Open Source Python API for Images

Library to add Image Processing Capabilities to your Python Interpreter.

Pillow is an open source Python API for image processing library designed to provide fast access to data stored in a few basic pixel formats. This open-source API supports a wide range of input and output image file formats with efficient internal representation and powerful image processing capabilities. Using the API, you can use the library to create thumbnails, convert between file formats, print images, and more.

Furthermore, using the API you can read bands, get modes, read image size, extract coordinated system, use filters, attach auxiliary information to an image, and get orientation tags.

Previous Next

Getting Started with Pillow

The recommended way to install pillow is via Pip. Please use the following command to install Pillow.

Install pillow via Pip

pip install pillow

Read & Write Images via Free Python API

Pillow API allows reading & writing images programmatically. In order to read images you can use open() method of the Image module. The library automatically detects the file format based on the content and you do not have to define the file format at the time of opening. Similarly, you can save the image using the save() method of the Image module. Furthermore, you can convert images to JPEG format, create JPEG thumbnails, identify image files, and more.

Create JPEG thumbnails via Python API

import os, sys
from PIL import Image

size = (128, 128)

for infile in sys.argv[1:]:
    outfile = os.path.splitext(infile)[0] + ".thumbnail"
    if infile != outfile:
        try:
            with Image.open(infile) as im:
                im.thumbnail(size)
                im.save(outfile, "JPEG")
        except OSError:
            print("cannot create thumbnail for", infile)

Geometrical Transformations Using Free Python API

The Open Source image library pillow allows working geometrical transformations of images via python. Using the API, you can resize and rotate images using resize() & rotate() of PIL.Image.Image class. In order to rotate an image you can use rotate() or transpose() method. Using transpose() method you can use Image properties like ROTATE_90, ROTATE_180, ROTATE_270, FLIP_LEFT_RIGHT, and FLIP_TOP_BOTTOM.

Transposing an Image using Python

out = im.transpose(Image.Transpose.FLIP_LEFT_RIGHT)
out = im.transpose(Image.Transpose.FLIP_TOP_BOTTOM)
out = im.transpose(Image.Transpose.ROTATE_90)
out = im.transpose(Image.Transpose.ROTATE_180)
out = im.transpose(Image.Transpose.ROTATE_270)

Image Enhancement via Free Python API

Pillow library allows developers to enhance images programmatically. The API has a number of methods to enhance your images. You can use pre-defined image filters by using the filter() method. Furthermore, you can use point() method can be manipulated & specific pixels in the image. By using the ImageEnhance module you can adjust contrast, brightness, color balance, and sharpness easily.

Apply Filters via Python API

from PIL import ImageFilter
out = im.filter(ImageFilter.DETAIL)
 English