Skip to content

Instantly share code, notes, and snippets.

Embed
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):
continue
filepath = os.path.join(folder, filename)
img = Image.open(filepath)
w = 1200
h = 1200
large_img = img.resize((w, h), Image.ANTIALIAS)
large_img.save(filepath)
thumbnail = img.resize((w/4, h/4), Image.ANTIALIAS)
thumbnail.save(folder + 'small/' + filename)
print('Resizing images...')
folder = './i/'
if not os.path.exists(folder + 'small/'):
os.makedirs(folder + 'small/')
resize_images_in(folder);
print('...done.')
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.