Operations such as resizing images and cropping them to get a selected part of the image are very common, but these operations may become tedious when tried programmatically. See how we can achieve these tasks.
In this recipe, we will use the
Pillow library to resize and crop images. As we already have the Pillow module installed, we don't have to worry about any installations. Let's jump into doing stuff.
resize.py, and paste the following code snippet:
from PIL import Image img = Image.open('sunset.jpg') resized = img.resize((256,256)) resized.save('sunset-resize.jpg', 'jpeg')