def resize_crop_image(image, dest_w, dest_h, pad_when_tall=False):
<EOL>dest_w = float(dest_w)<EOL>dest_h = float(dest_h)<EOL>dest_ratio = dest_w / dest_h<EOL>src_w = float(image.size[<NUM_LIT:0>])<EOL>src_h = float(image.size[<NUM_LIT:1>])<EOL>src_ratio = src_w / src_h<EOL>if src_ratio < dest_ratio:<EOL><INDENT>scale = dest_w / src_w<EOL>scaled_w = dest_w<EOL>scaled_h = src_h * scale<EOL>left = <NUM_LIT:0><EOL>right = dest_w<EOL>top = (scaled_h - dest_h) / <NUM_LIT><EOL>bottom = top + dest_h<EOL><DEDENT>else:<EOL><INDENT>scale = dest_h / src_h<EOL>scaled_h = dest_h<EOL>scaled_w = src_w * scale<EOL>left = (scaled_w - dest_w) / <NUM_LIT><EOL>right = left + dest_w<EOL>top = <NUM_LIT:0><EOL>bottom = dest_h<EOL><DEDENT>if pad_when_tall:<EOL><INDENT>if (bottom - top) < (scaled_h * <NUM_LIT>):<EOL><INDENT>log.info('<STR_LIT>')<EOL>return resize_pad_image(image, dest_w, dest_h)<EOL><DEDENT><DEDENT>if src_w > dest_w or src_h > dest_h:<EOL><INDENT>scaled_image = image.resize((int(scaled_w), int(scaled_h)), PIL.Image.ANTIALIAS)<EOL>cropped_image = scaled_image.crop((int(left), int(top), int(right), int(bottom)))<EOL>return cropped_image<EOL><DEDENT>elif scaled_w < src_w or scaled_h < src_h:<EOL><INDENT>cropped_image = image.crop((int(left), int(top), int(right), int(bottom)))<EOL>return cropped_image<EOL><DEDENT>else:<EOL><INDENT>return image<EOL><DEDENT>
:param image: PIL.Image
:param dest_w: Target width
:param dest_h: Target height
:return: Scaled and cropped image