Last active
March 11, 2017 14:14
-
-
Save princewang1994/a786185e1415dad1645ad78526053d06 to your computer and use it in GitHub Desktop.
PIL compress image
This file contains 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 Image | |
import os | |
import os.path | |
import sys | |
path = sys.argv[1] | |
small_path = (path[:-1] if path[-1]=='/' else path) +'_small' | |
if not os.path.exists(small_path): | |
os.mkdir(small_path) | |
for root, dirs, files in os.walk(path): | |
for f in files: | |
fp = os.path.join(root, f) | |
img = Image.open(fp) | |
w, h = img.size | |
img.resize((w/2, h/2)).save(os.path.join(small_path, f), "JPEG") | |
print fp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment