def fit_image(width, height, pwidth, pheight):
 scaled = ((height > pheight) or (width > pwidth))
 if (height > pheight):
  corrf = (pheight / float(height))
  (width, height) = (floor((corrf * width)), pheight)
 if (width > pwidth):
  corrf = (pwidth / float(width))
  (width, height) = (pwidth, floor((corrf * height)))
 if (height > pheight):
  corrf = (pheight / float(height))
  (width, height) = (floor((corrf * width)), pheight)
 return (scaled, int(width), int(height))

def fit_image ( width , height , pwidth , pheight ) : scaled = ( ( height > pheight ) or ( width > pwidth ) ) if ( height > pheight ) : corrf = ( pheight / float ( height ) ) ( width , height ) = ( floor ( ( corrf * width ) ) , pheight ) if ( width > pwidth ) : corrf = ( pwidth / float ( width ) ) ( width , height ) = ( pwidth , floor ( ( corrf * height ) ) ) if ( height > pheight ) : corrf = ( pheight / float ( height ) ) ( width , height ) = ( floor ( ( corrf * width ) ) , pheight ) return ( scaled , int ( width ) , int ( height ) )
fit image in box of width pwidth and height pheight .