Skip to content

Instantly share code, notes, and snippets.

@omiq
Created January 24, 2018 20:16
Show Gist options
  • Save omiq/60df574fb3f9d8ddaab0a8a6bc8615e8 to your computer and use it in GitHub Desktop.
Save omiq/60df574fb3f9d8ddaab0a8a6bc8615e8 to your computer and use it in GitHub Desktop.
How to Automagically Create Thumbnail Images Using Python
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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment