Created
May 11, 2017 14:40
-
-
Save smokinggoats/a462bdc3411c2230cff1969823d094e8 to your computer and use it in GitHub Desktop.
Generate thumb images
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
from PIL import Image | |
import sys | |
import os | |
import glob | |
thumb_size = (256, 256) | |
def main(path): | |
if (path[0] != '/'): | |
path = os.path.abspath(path) | |
files = glob.glob(os.path.join(path, '*')) | |
for f in files: | |
file_path, file_name = f.rsplit('/', 1) | |
file_type = file_name.rsplit('.', 1)[1] | |
thumb_path = os.path.join(file_path, | |
'thumb-{}'.format(file_name)) | |
thumb = Image.open(f) | |
thumb.thumbnail(thumb_size) | |
thumb.save(thumb_path, 'JPEG', quality=70) | |
if __name__ == '__main__': | |
if len(sys.argv) == 2: | |
main(sys.argv[1]) | |
else: | |
print('Wrong number of arguments') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment