#NEWLINE# def scale_to_max_size( image , max_width , max_height ) : #NEWLINE# #INDENT# "Returns an image, that isn't bigger than max_width and max_height.\n\n    That means one side is exactly given value and the other is smaller. In\n    other words the image fits at any rate in the given box max_width x\n    max_height.\n    " #NEWLINE# ( width , height ) = image . size #NEWLINE# prop_width = ( float ( max_width ) / width ) #NEWLINE# prop_height = ( float ( max_height ) / height ) #NEWLINE# if ( prop_height < prop_width ) : #NEWLINE# #INDENT# width = int ( ( prop_height * width ) ) #NEWLINE# image = image . resize ( ( width , max_height ) , Image . ANTIALIAS ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# height = int ( ( prop_width * height ) ) #NEWLINE# image = image . resize ( ( max_width , height ) , Image . ANTIALIAS ) #NEWLINE# #UNINDENT# return image