Subversion Repositories SmartDukaan

Rev

Rev 18920 | Rev 19445 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
938 rajveer 1
from PIL import Image
2
import glob, os, sys, shutil
3
 
4
 
5
if len(sys.argv) < 5:
6
    print "usage: {infile, outfile, width, height}"
7
    sys.exit(1)
8
 
9
default_image = "./default.jpg"
10
dirs = os.listdir("./")
11
for dir in dirs:
12968 amit.gupta 12
    if os.path.isdir(os.path.join("./", dir)):
13
        infile = dir + "/" + sys.argv[1]
14
        if not os.path.isfile(infile):
15
            shutil.copy2(default_image, infile)
16
        outfile = dir + "/" + sys.argv[2]
13096 amit.gupta 17
        if not (os.path.isfile(outfile) and os.path.getmtime(outfile) > os.path.getmtime(infile)):
18921 amit.gupta 18
            sys.stderr.write(infile)
12968 amit.gupta 19
            width = int(sys.argv[3])
20
            height = int(sys.argv[4])
21
            size = width, height
22
            im = Image.open(infile)
23
            im.thumbnail(size, Image.ANTIALIAS)
24
            im.save(outfile, "JPEG")