Subversion Repositories SmartDukaan

Rev

Rev 19449 | 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:
19740 amit.gupta 12
    try:
13
        if os.path.isdir(os.path.join("./", dir)):
14
            infile = dir + "/" + sys.argv[1]
15
            if not os.path.isfile(infile):
16
                print "file is missing\n"
17
                shutil.copy2(default_image, infile)
18
            if os.stat(infile).st_size==0:
19
                print "file is of 0 size\n"
20
                continue
21
                #shutil.copy2(default_image, infile)
22
            outfile = dir + "/" + sys.argv[2]
23
            if not (os.path.isfile(outfile) and os.path.getmtime(outfile) > os.path.getmtime(infile)):
24
                sys.stderr.write(infile)
25
                width = int(sys.argv[3])
26
                height = int(sys.argv[4])
27
                size = width, height
28
                im = Image.open(infile)
29
                im.thumbnail(size, Image.ANTIALIAS)
30
                im.save(outfile, "JPEG")
31
    except:
32
        print "moving on"