def _scale_to_fit(width, height, max_width, max_height):
    """scales input dimensions to fit within max dimensions"""
    height_scale = height/max_height
    width_scale = width/max_width
    scale = max(height_scale, width_scale)
    if scale > 1:
        height /= scale
        width /= scale
    return width, height