Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python Image Resizer
import os
import sys
from PIL import Image
def is_image(filename):
return filename[-3:].lower() in ["png", "jpg", "jpeg", "bmp"]
def resize_images_in(folder):
for filename in os.listdir(folder):
if not is_image(filename):
filepath = os.path.join(folder, filename)
img =
w = 1200
h = 1200
large_img = img.resize((w, h), Image.ANTIALIAS)
thumbnail = img.resize((w/4, h/4), Image.ANTIALIAS) + 'small/' + filename)
print('Resizing images...')
folder = './i/'
if not os.path.exists(folder + 'small/'):
os.makedirs(folder + 'small/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.