Subversion Repositories SmartDukaan

Rev

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