• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
  • YouTube
  • MakerWorld
  • Instagram
  • Threads
  • Bluesky
  • Mastodon
  • Facebook
makerhacks-logo

Maker Hacks

Ideas, news & tutorials for makers and hackers – Arduino/Raspberry Pi, 3D printing, robotics, laser cutting, and more

  • Home
  • About
  • 3D Printing
  • Laser Cutting
  • CNC
  • Programming
  • Free Arduino Course
  • Free Robotics Course
  • Recommendations

How to Automagically Create Thumbnail Images Using Python

You are here: Home / Software and Programming / How to Automagically Create Thumbnail Images Using Python
Author: Chris Garrett
thumbnails with python
Some thumbnails generated with python

Formatting round-up posts takes a bit of effort so I have been looking for ways to make the non-creative work as automated as possible. One of these tasks is creating thumbnails. Turns out it is really easy to do with Python and does not involve calling the command line ImageMagick tool.

All the examples I found talked about using Image. Unfortunately, I immediately had an issue where my version of Python could not find any Image library. You might find it outputs the same error yourself:

ModuleNotFoundError: No module named ‘Image’

A solution is to instead use PIL:
pip install pil

That worked great on my dev server, but on my Mac not so much. I got the following error message:

Could not find a version that satisfies the requirement pil (from versions: )
No matching distribution found for pil

Locally I needed to use Pillow instead:
pip3 install pillow

Ta-da, it worked!

Python Code

This code will read the JPG images in the current directory and if one does not already exist, generates a thumbnail with T_ filename.

As well as the Image class, we use Glob to make the file path easier:

The glob module finds all the pathnames matching a specified pattern according to the rules used by the Unix shell

import glob
from PIL import Image


# get all the jpg files from the current folder
for infile in glob.glob("*.jpg"):
  im = Image.open(infile)
  # convert to thumbnail image
  im.thumbnail((128, 128), Image.ANTIALIAS)
  # don't save if thumbnail already exists
  if infile[0:2] != "T_":
    # prefix thumbnail file with T_
    im.save("T_" + infile, "JPEG")

Category: Software and ProgrammingTag: Hacks, python, tips, web development

About Chris Garrett

Marketing nerd by day, maker, retro gaming, tabletop war/roleplaying nerd by night. Co-author of the Problogger Book with Darren Rowse. Husband, Dad, 🇨🇦 Canadian.

Check out Retro Game Coders for retro gaming/computing.

☕️ Support Chris on Ko-Fi to get exclusive content and rewards!

Previous Post:Grove i2c LCDPlaying with Grove – LCD Displays
Next Post:Cheap solution for WiFi dead spots – TP-Link PowerLine Ethernet ReviewTP Link Powerline Ethernet Adapter

Sidebar

  • Facebook
  • Instagram
  • YouTube

Featured Posts

  • CyberBrick Review + Getting Started
  • xTool M2 Review
  • xTool F2 Ultra Review
  • xTool F2 Review
  • xTool S1 Review
  • Anycubic Kobra S1 Combo Review
  • Makera Z1 Pro Review
  • CNC Buyer's Guide
  • eufyMake E1 UV Printer Review
  • eufyMake Purifier P1
  • Z80 on a Breadboard
  • OpenSCAD MakerWorld Customizer

30 Days to Arduino

Arduino Tutorials
  • 3D Printing
  • CNC
  • Electronics and Hardware
  • Laser Cutting
  • News and Reviews
  • Software and Programming

arduino budget cad cnc diode laser glowforge Hacks Ideas laser cutter linux Makes making python raspberry pi Reviews technology tips xtool xTool Lasers

  • YouTube
  • MakerWorld
  • Instagram
  • Threads
  • Bluesky
  • Mastodon
  • Facebook

.

Maker Hacks Blog Copyright © 2026 · All Rights Reserved · Privacy Policy