def scale_image(self, in_fname, out_fname, max_width, max_height):
<EOL>try:<EOL><INDENT>from PIL import Image<EOL><DEDENT>except ImportError:<EOL><INDENT>import Image<EOL><DEDENT>img = Image.open(in_fname)<EOL>width_in, height_in = img.size<EOL>scale_w = max_width / float(width_in)<EOL>scale_h = max_height / float(height_in)<EOL>if height_in * scale_w <= max_height:<EOL><INDENT>scale = scale_w<EOL><DEDENT>else:<EOL><INDENT>scale = scale_h<EOL><DEDENT>if scale >= <NUM_LIT:1.0> and in_fname == out_fname:<EOL><INDENT>return<EOL><DEDENT>width_sc = int(round(scale * width_in))<EOL>height_sc = int(round(scale * height_in))<EOL>img.thumbnail((width_sc, height_sc), Image.ANTIALIAS)<EOL>thumb = Image.new('<STR_LIT>', (max_width, max_height), (<NUM_LIT:255>, <NUM_LIT:255>, <NUM_LIT:255>))<EOL>pos_insert = (<EOL>(max_width - width_sc) // <NUM_LIT:2>, (max_height - height_sc) // <NUM_LIT:2>)<EOL>thumb.paste(img, pos_insert)<EOL>thumb.save(out_fname)<EOL>
Scales an image with the same aspect ratio centered in an
           image with a given max_width and max_height
           if in_fname == out_fname the image can only be scaled down