Skip to content

Instantly share code, notes, and snippets.

@akarsh1995
Created July 25, 2020 15:18
Show Gist options
  • Select an option

  • Save akarsh1995/637d78d6e1782921dad5c405f4a6df59 to your computer and use it in GitHub Desktop.

Select an option

Save akarsh1995/637d78d6e1782921dad5c405f4a6df59 to your computer and use it in GitHub Desktop.
Create thumbnail for all the images in a directory.
SIZE_THUMBS = (75, 75)
FROM_DIR = 'images'
TO_DIR = 'thumbs'
if __name__ == '__main__':
import os
if not os.path.exists(TO_DIR):
os.mkdir(TO_DIR)
import glob
for filename in glob.glob(FROM_DIR + "/*.*p*g"):
filename_thumbnail = os.path.join(TO_DIR, os.path.split(filename)[1])
print('{} -> {}'.format(filename, filename_thumbnail))
from PIL import Image
im = Image.open(filename)
im.thumbnail(SIZE_THUMBS)
im.save(filename_thumbnail)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment