Wat!

Batch resizing images with Python and Pillow

Pillow is a fork of PIL (Python Imaging Library) which works on Python 3. It provides convenient methods to manipulate and convert image files with just a few lines of code. Usually every mobile application platform requires the same image to be provided in multiple sizes, and since resizing these images manually can be cumbersome, Pillow and Python can come to save the day by automating these processes.

from PIL import Image
 
inputName = "image.png"
sizes = (512, 256, 128, 64, 32)
 
img = Image.open(inputName)
for size in sizes:
    name = "{}-{}.png".format(inputName, size)
    resizedImage = img.resize((size, size), Image.ANTIALIAS)
    resizedImage.save(name)

To install Pillow using pip, you can simply execute:

pip install Pillow
Sam Afshari's Notes February 24, 2016

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.

An unhandled error has occurred. Reload 🗙