Created
December 1, 2018 07:51
-
-
Save 45deg/dc50fd761e83e54fe382990ffac18032 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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