Create thumbnail images using python image library


SUBMITTED BY: Bun

DATE: Feb. 16, 2016, 11:15 a.m.

FORMAT: Python 3

SIZE: 417 Bytes

HITS: 787

  1. import os, sys
  2. import Image
  3. size = 128, 128
  4. for imgfiles in sys.argv[1:]:
  5. outimg = os.path.splitext(imgfiles)[0] + ".thumbnail"
  6. if imgfiles != outimg:
  7. try:
  8. imthumb = Image.open(imgfiles)
  9. imthumb.thumbnail(size, Image.ANTIALIAS)
  10. imthumb.save(outimg, "JPEG")
  11. except IOError:
  12. print ("thumbnail cannot be created for '%s'") % imgfiles

comments powered by Disqus