Subversion Repositories SmartDukaan

Rev

Rev 19448 | Rev 19740 | 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):
19449 amit.gupta 15
            print "file is missing\n"
12968 amit.gupta 16
            shutil.copy2(default_image, infile)
19448 amit.gupta 17
        if os.stat(infile).st_size==0:
19449 amit.gupta 18
            print "file is of 0 size\n"
19448 amit.gupta 19
            continue
20
            #shutil.copy2(default_image, infile)
12968 amit.gupta 21
        outfile = dir + "/" + sys.argv[2]
19446 amit.gupta 22
        if not (os.path.isfile(outfile) and os.path.getmtime(outfile) > os.path.getmtime(infile)):
18921 amit.gupta 23
            sys.stderr.write(infile)
12968 amit.gupta 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")