Created
June 13, 2017 12:48
-
-
Save kkeybbs/f447690c67b7d4e327e7db0e349290b2 to your computer and use it in GitHub Desktop.
image_resize.py
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
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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment