Image uploads with Django forms
If you want to work with images in Python, the most common library that you’ll use is called Pillow
, and this is the library Django uses to validate images. Originally there was a library called Python Imaging Library (PIL). It was not kept up to date and, eventually, a fork of the library was created and is still maintained, Pillow
. To maintain backward compatibility, the package is still called PIL
when installed. For example, the Image
object is imported from PIL
:
from PIL import Image
The terms Python Imaging Library, PIL, and Pillow are often used interchangeably. You can assume that if someone refers to PIL, they mean the latest Pillow library.
Pillow provides various methods of retrieving data about images or manipulating them. You can find out the width and height of images, scale, crop, and apply transformations to them. There are too many operations available to cover in this chapter, so we will just introduce a simple example...