Generate thumbnail using Python

Posted by Afsal on 14-Apr-2023

Hi Pythonistas!

Today we will learn how to generate a thumbnail image from an Image. We are using the PIL(pillow) library for this. Only 4 lines of code do the task. Let us check with an example

Installation

pip install  Pillow

Code

from PIL import Image

 image = Image.open("logo.jpg")

image.thumbnail((100, 100))

image.save('logo_thump.jpg')

Replace the logo.jpg with the image you want. Also, change logo_thump.jpg to the name you want to save. 100, 100 is the size of the thumbnail. Once the code is executed the thumbnail will be generated in the same folder as the script

Hope you have learned something from this post. Please do share your valuable suggestions with afsal@parseltongue.co.in