• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
Maker Hacks

Maker Hacks

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

  • Home
  • About
  • YouTube
  • Recommendations
  • Contact

How to Automagically Create Thumbnail Images Using Python

You are here: Home / Hacks, Tips, and Tutorials / How to Automagically Create Thumbnail Images Using Python
FacebookTweetPin
Author: Chris Garrett

On my blog at Steemit I have been posting roundups of the best links I have found, either on Steemit itself, or around the web. Formatting these 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!

thumbnails with python
Some thumbnails generated with 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

Related

Category: Hacks, Tips, and TutorialsTag: programming, python, tips, web development
FacebookTweetPin

About Chris Garrett

Marketing Director 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 Maker Hacks on Ko-Fi and 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
  • Twitter
  • Instagram
  • YouTube

Recently Popular

  • Gweike Cloud Review
  • How to choose the right 3D printer for you
  • Glowforge Review – Glowforge Laser Engraver Impressions, Plus Glowforge Versus Leading Laser Cutters
  • Original Prusa i3 Mk3S Review
  • Best 3D Printing Facebook Groups
  • Elegoo Mars Review – Review of the Elegoo Mars MSLA Resin 3D Printer
  • Glowforge ‘Pass-Through’ Hack: Tricking the Front Flap of the Glowforge with Magnets to Increase Capacity
  • How to Make a DIY “Internet of Things” Thermometer with ESP8266/Arduino
  • Wanhao Duplicator i3 Review
  • IKEA 3D Printer Enclosure Hack for Wanhao Di3
  • Creality CR-10 3d printer review – Large format, quality output, at a low price!
  • 3D Printed Tardis with Arduino Lights and Sounds
  • Anet A8 Review – Budget ($200 or less!) 3D Printer Kit Review
  • Make your own PEI 3D printer bed and get every print to stick!
  • Upgrading the Wanhao Di3 from Good to Amazing
  • How to Install and Set Up Octopi / Octoprint
  • Creality CR-10 S5 Review

Copyright © 2023 · Maker Hacks · All Rights Reserved · Powered by Mai Theme