image_resize.py
import os
from PIL import Image
files = os.listdir('.')
files = filter(lambda x: not x.endswith('.py') and not x.startswith('ex_'), files)
sizes = set()
min_size = 600
for file in files:
im = Image.open(file)
if im.size[0] > im.size[1]:
im = im.resize((int(1.0 * im.size[0] / im.size[1] * min_size), min_size))
else:
im = im.resize((min_size, int(1.0 * im.size[1] / im.size[0] * min_size)))
im.save('ex_' + file)
print('Task Done')