def apply_ratio(o_w, o_h, t_w, t_h):
    """Calculate width or height to keep aspect ratio.

    o_w, o_h -- origin width and height
    t_w, t_h -- target width or height, the dimension
                to be calculated must be set to 0.
    
    Returns: (w, h) -- the new dimensions
    """
    new_w = t_h * o_w / o_h
    new_h = t_w * o_h / o_w
    return new_w+t_w, new_h+t_h