def scale_ratio(src_width, src_height, dest_width, dest_height):
    """Return a size fitting into dest preserving src's aspect ratio."""
    if src_height > dest_height:
        if src_width > dest_width:
            ratio = min(float(dest_width) / src_width,
                        float(dest_height) / src_height)
        else:
            ratio = float(dest_height) / src_height
    elif src_width > dest_width:
        ratio = float(dest_width) / src_width
    else:
        ratio = 1
    return int(ratio * src_width), int(ratio * src_height)