Skip to content

Instantly share code, notes, and snippets.

@fcgomes92
Created May 11, 2017 14:40
Show Gist options
  • Save fcgomes92/a462bdc3411c2230cff1969823d094e8 to your computer and use it in GitHub Desktop.
Save fcgomes92/a462bdc3411c2230cff1969823d094e8 to your computer and use it in GitHub Desktop.
Generate thumb images
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