def rescale(img, size, mode=None):
assert size[<NUM_LIT:0>] or size[<NUM_LIT:1>], "<STR_LIT>"<EOL>size = list(size)<EOL>crop = size[<NUM_LIT:0>] and size[<NUM_LIT:1>]<EOL>if not size[<NUM_LIT:0>]:<EOL><INDENT>size[<NUM_LIT:0>] = int(img.size[<NUM_LIT:0>] * size[<NUM_LIT:1>] / float(img.size[<NUM_LIT:1>]))<EOL><DEDENT>if not size[<NUM_LIT:1>]:<EOL><INDENT>size[<NUM_LIT:1>] = int(img.size[<NUM_LIT:1>] * size[<NUM_LIT:0>] / float(img.size[<NUM_LIT:0>]))<EOL><DEDENT>if crop:<EOL><INDENT>b = img.size[<NUM_LIT:0>] > img.size[<NUM_LIT:1>]<EOL>crop_size = (img.size[b], int(img.size[b] * size[<NUM_LIT:0>] / float(size[<NUM_LIT:1>])))<EOL>if mode ==  CROP_TL:<EOL><INDENT>img = img.crop((<NUM_LIT:0>, <NUM_LIT:0>, crop_size[<NUM_LIT:0>], crop_size[<NUM_LIT:1>]))<EOL><DEDENT>elif mode == CROP_BR:<EOL><INDENT>img = img.crop((<EOL>img.size[<NUM_LIT:0>] - crop_size[<NUM_LIT:0>],<EOL>img.size[<NUM_LIT:1>] - crop_size[<NUM_LIT:1>],<EOL>img.size[<NUM_LIT:0>],<EOL>img.size[<NUM_LIT:1>]<EOL>))<EOL><DEDENT><DEDENT>return img.resize(size, Image.ANTIALIAS)<EOL>
Rescale an image to given size, crop if mode specified
 * img: a PIL image object
 * size: a 2-tuple of (width, height); at least one must be specified
 * mode: CROP_TL keep the top left part, CROP_BR the bottom right part