def resize(image, x, y, stretch=False, top=None, left=None, mode='<STR_LIT>',<EOL>resample=None):
if x <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if y <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>from PIL import Image<EOL>resample = Image.ANTIALIAS if resample is None else resample<EOL>if not isinstance(resample, numbers.Number):<EOL><INDENT>try:<EOL><INDENT>resample = getattr(Image, resample.upper())<EOL><DEDENT>except:<EOL><INDENT>raise ValueError("<STR_LIT>" % resample)<EOL><DEDENT>if not isinstance(resample, numbers.Number):<EOL><INDENT>raise ValueError("<STR_LIT>" % resample)<EOL><DEDENT><DEDENT>size = x, y<EOL>if stretch:<EOL><INDENT>return image.resize(size, resample=resample)<EOL><DEDENT>result = Image.new(mode, size)<EOL>ratios = [d1 / d2 for d1, d2 in zip(size, image.size)]<EOL>if ratios[<NUM_LIT:0>] < ratios[<NUM_LIT:1>]:<EOL><INDENT>new_size = (size[<NUM_LIT:0>], int(image.size[<NUM_LIT:1>] * ratios[<NUM_LIT:0>]))<EOL><DEDENT>else:<EOL><INDENT>new_size = (int(image.size[<NUM_LIT:0>] * ratios[<NUM_LIT:1>]), size[<NUM_LIT:1>])<EOL><DEDENT>image = image.resize(new_size, resample=resample)<EOL>if left is None:<EOL><INDENT>box_x = int((x - new_size[<NUM_LIT:0>]) / <NUM_LIT:2>)<EOL><DEDENT>elif left:<EOL><INDENT>box_x = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>box_x = x - new_size[<NUM_LIT:0>]<EOL><DEDENT>if top is None:<EOL><INDENT>box_y = int((y - new_size[<NUM_LIT:1>]) / <NUM_LIT:2>)<EOL><DEDENT>elif top:<EOL><INDENT>box_y = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>box_y = y - new_size[<NUM_LIT:1>]<EOL><DEDENT>result.paste(image, box=(box_x, box_y))<EOL>return result<EOL>
Return an image resized.