The Python Imaging Library(PIL) is one of the core libraries for manipulating image in Python. Unfortunately, its development has stagnated since 2009. Luckily, there is an actively-developed fork of PIL called Pillow. This tutorial will use Pillow to resize image.
pip install Pillow
#!/usr/bin/python3 from PIL import Image # Set your resize size. size = (128, 128) try: im = Image.open("wildlife.jpg") im.thumbnail(size) # thumbnail() will preserve the aspect ratio of the original image. im.save("wildlife-thumbnail.jpg", "JPEG") except IOError: print("Cannot resize image.")