Python Pillow – Create a Thumbnail

This tutorial explains how to create a thumbnail in Pillow

Thumbnails are reduced-size versions of pictures or even videos used to help recognize them, especially during storage. A very common usage of thumbnails you see everyday is the image showing on a video before you actually play it.

Another common example is when you are searching for images in your computer. Before you actually click on the image to view it, you can see a small low-res version of the actual image, which acts as a icon.


Creating Thumbnails

Another thing you have to decide for your thumbnails is the dimensions. Usually a square format is followed, but sometimes the 16:9 dimensions are used (e.g: YouTube videos).

Unlike most of Pillow’s other functions, the thumbnail function actually effects the image object instead of creating a duplicate with the adjusted values. So don’t go around saving it overwriting your original by accident.

from PIL import Image

img = Image.open("C://Users/Coderslegacy/Desktop/kitten.jpg")

thumb_size = (100, 100)

img.thumbnail(thumb_size)
img.show()

Here’s the image we’ll be running our code on.

Python Pillow create thumbnail

The output thumbnail produced by our code:

pillow kitten thumbnail

That’s quite the drastic change, but it was effective. We can still make out the general image from the thumbnail.


This marks the end of the Pillow “Create a Thumbnail” tutorial. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the article content can be asked in the comments section below.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments