Subversion Repositories SmartDukaan

Rev

Rev 19445 | Rev 19447 | 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):
19446 amit.gupta 15
            print "file is missing"
12968 amit.gupta 16
            shutil.copy2(default_image, infile)
19446 amit.gupta 17
        elif not os.stat(infile).st_size==0:
18
            print "file is of 0 size"
19
            shutil.copy2(default_image, infile)
12968 amit.gupta 20
        outfile = dir + "/" + sys.argv[2]
19446 amit.gupta 21
        if not (os.path.isfile(outfile) and os.path.getmtime(outfile) > os.path.getmtime(infile)):
18921 amit.gupta 22
            sys.stderr.write(infile)
12968 amit.gupta 23
            width = int(sys.argv[3])
24
            height = int(sys.argv[4])
25
            size = width, height
26
            im = Image.open(infile)
27
            im.thumbnail(size, Image.ANTIALIAS)
28
            im.save(outfile, "JPEG")