4 from os.path import splitext, dirname, basename, realpath
8 def crop(image, top=0, right=0, bottom=0, left=0):
9 width, height = image.size
11 top = int(height * top)
13 right = int(width * right)
15 bottom = int(height * bottom)
17 left = int(width * left)
19 bounds = (int(left), int(top), int(width - right), int(height - bottom))
20 image = image.crop(bounds)
25 output_dir = realpath(os.getcwd()) + '/output'
26 bounds = [float(i) for i in sys.argv[1].split(':')]
28 for file_name in sys.argv[2:]:
29 base_name, ext = splitext(file_name)
31 image = Image.open(file_name)
33 sys.stderr.write('\nerror:%s:%s\n' % (file_name, e.message))
36 image = crop(image, *bounds)
37 image.save(output_dir + '/' + basename(file_name))