Permalink
Browse files

thumbnail generator

  • Loading branch information...
lycarter committed Mar 18, 2018
1 parent c3ceb52 commit 46473e3efa922c3f4e51ba9b60872bebbe16de6e
Showing with 36 additions and 0 deletions.
  1. +36 −0 scripts/thumbnail_generator.py
@@ -0,0 +1,36 @@
#!/usr/bin/env python
from PIL import Image
import os, sys
def resizeImage(infile, suffix="_thumb", output_dir="", size=(1024,768)):
filename = os.path.splitext(os.path.basename(infile))[0]
outfile = os.path.join(output_dir, filename)+suffix+".jpg"
if infile != outfile:
try :
print(infile)
print(outfile)
print("opening")
im = Image.open(infile)
print("opened")
im.thumbnail(size, Image.ANTIALIAS)
print("resized")
im.save(outfile,"JPEG")
print("saved")
except IOError:
print("cannot reduce image for %s" % infile)
if __name__=="__main__":
output_dir_name = "thumbnail"
img_dir = os.path.join(os.getcwd(), "../assets/img")
if not os.path.exists(os.path.join(img_dir,output_dir_name)):
os.mkdir(os.path.join(img_dir,output_dir))
for file in os.listdir(img_dir):
infile = os.path.join(img_dir,file)
outdir = os.path.join(img_dir,output_dir_name)
resizeImage(infile, "_thumb_200", outdir, (200,200))
resizeImage(infile, "_thumb_800", outdir, (800,800))

0 comments on commit 46473e3

Please sign in to comment.