Pillow Introduction

Pillow is an open-source Python library that is used for image processing developed by Secret Labs AB. It is released under the Python Imaging Library license.


History

Fredrik Lundh and contributors started the Python Imaging Library, also known as PIL. Pillow is a friendly fork of the PIL library by Alex Clark and contributors.


A brief introduction to Pillow

Pillow library can be used for basic to fairly powerful image handling and image processing tasks. It is easy and simple to use the library for a varying range of image processing tasks. Pillow can be used for a variety of basic tasks such as opening image files, resizing, rotating, transposing, cropping, and pasting images. It can also be used for powerful tasks such as enhancing images, apply filters to them, performing color and type conversion on images, and, drawing shapes and writing texts on the Images among other operations.


Do you have Pillow?

You can check if you already have Pillow installed by running the following command in your Python interpreter or Jupyter Notebook.

import PIL

If you don’t have Pillow installed, an error message similar to the one below will be displayed.

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PIL'

However, if no such error message appears, then Pillow is already installed and you are good to continue with the rest of this Pillow tutorial.

Note– You might find it uncomfortable in the beginning that Pillow is imported using the command import PIL. However, you will get used to it.


Installing Pillow

Pillow is easy to install. The procedure for installing it depends on your package manager.

Before Installing Pillow, it is important to know that Pillow and PIL packages cannot co-exist together. Therefore, if you already have PIL installed, you need to uninstall it before installing PIL.

Installing Pillow using Pip

Pip is the default package management system for python. Therefore, it comes bundled with your python interpreter and is not required to be installed separately. To install Pillow using pip, simply run the following command

pip install Pillow

Installing Pillow using Conda

Conda is the default package manager of the Anaconda distribution, which is just a bunch of data science packages bundled together. As a result, it comes bundled with the anaconda distribution. If you use the Anaconda distribution, you should be using conda to manage your packages and hence to install Pillow. To install Pillow using conda, simply run the following command.

conda install -c anaconda pillow

Checking Pillow Version

You can check the version of Pillow you are using by running the following command

print(PIL.__version__)

This Pillow tutorial is written using the Pillow 6.2.0 version, therefore it is recommended to use any of the 6.2.x version or at least a 6.x version.

Note– It is also recommended that you use Python 3 instead of Python 2 for this tutorial.

With Pillow installed on your system, and having a brief introduction about Pillow, you are good to follow along with this Pillow tutorial.