def clip_line(line, size):
    """
    :param line: (xmin, ymin, xmax, ymax)
    :param size: (height, width)
    :return: (xmin, ymin, xmax, ymax)
    """
    xmin, ymin, xmax, ymax = line

    if xmin < 0:
        xmin = 0
    if xmax > size[1] - 1:
        xmax = size[1] - 1
    if ymin < 0:
        ymin = 0
    if ymax > size[0] - 1:
        ymax = size[0] - 1

    return xmin, ymin, xmax, ymax