Python Pillow is a great image editing module that allows you to perform a number of image editing tasks using Python.
Examples of things you can do are:
- Edit the image size and dimensions
- Rotate an image
- Change the brightness of an image
- Edit the colors of individual pixels in an image
This is especially useful if you need to process a large number of images using the same process!
Pillow usually does not come installed as standard, so you may need to install it on your computer first to use it.
Before we try to edit the image, we should first get a feel for the program.
Download the image below and save it to a folder on your computer. Open the CMD/Terminal program and navigate to the correct folder that you just saved the file to.
Once you are in the correct folder in the terminal open up the Python interactive interpreter by typing python or python3.
Inside the interpreter import the Image class from Pillow and load the image by typing:
from PIL import Image im = image.open('dogememe.png')
If you have any problems opening the file check that you opened Python in the same directory as where the image is located (leave Python and type ls or dir to check you can see the image).
Investigate the image.
Try out the following code and see what each one does.
Try the following code
What do you see? What do the numbers represent?