def resize_image_to_fit(image, dest_w, dest_h):
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_h / src_h<EOL>scaled_h = dest_h<EOL>scaled_w = src_w * scale<EOL><DEDENT>else:<EOL><INDENT>scale = dest_w / src_w<EOL>scaled_w = dest_w<EOL>scaled_h = src_h * scale<EOL><DEDENT>scaled_image = image.resize((int(scaled_w), int(scaled_h)), PIL.Image.ANTIALIAS)<EOL>return scaled_image<EOL>
Resize the image to fit inside dest rectangle.  Resultant image may be smaller than target
:param image: PIL.Image
:param dest_w: Target width
:param dest_h: Target height
:return: Scaled image