Skip to content

Instantly share code, notes, and snippets.

@45deg
Created December 1, 2018 07:51
Show Gist options
  • Save 45deg/dc50fd761e83e54fe382990ffac18032 to your computer and use it in GitHub Desktop.
Save 45deg/dc50fd761e83e54fe382990ffac18032 to your computer and use it in GitHub Desktop.
from PIL import Image
from multiprocessing import Pool
import glob
LIMIT = 1920
def resize(file):
im = Image.open(file)
(ow, oh) = im.size
if ow >= oh and ow > LIMIT:
out = im.resize((LIMIT, round(LIMIT * oh/ow)), Image.LANCZOS)
elif oh >= ow and ow:
out = im.resize((round(LIMIT * ow/oh), LIMIT), Image.LANCZOS)
else:
out = im
out.save("result/" + file.split('/')[-1].split('.')[0] + ".png")
print("resized " + file)
files = sorted(glob.glob("orig/*.png") + glob.glob("orig/*.PNG"))
with Pool(processes=4) as pool:
pool.map(resize, files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment