'**SUMMARY**
Returns the line with endpoints on edges of image.
**RETURNS**
Returns a :py:class:`Line` object. If line does not lies entirely inside image then returns None.
**EXAMPLE**
>>> img = Image("lenna")
>>> l = Line(img, ((50, 150), (2, 225))
>>> cr_l = l.extendToImageEdges()'

def extendToImageEdges(self):

    (pt1, pt2) = self.end_points
    (pt1, pt2) = (min(pt1, pt2), max(pt1, pt2))
    (x1, y1) = pt1
    (x2, y2) = pt2
    (w, h) = ((self.image.width - 1), (self.image.height - 1))
    slope = self.slope
    if ((not (0 <= x1 <= w)) or (not (0 <= x2 <= w)) or (not (0 <= y1 <= w)) or (not (0 <= y2 <= w))):
        logger.warning('At    first    the    line    should    be    cropped')
        return None
    ep = []
    if (slope == float('inf')):
        if ((0 <= x1 <= w) and (0 <= x2 <= w)):
            return Line(self.image, ((x1, 0), (x2, h)))
    elif (slope == 0):
        if ((0 <= y1 <= w) and (0 <= y2 <= w)):
            return Line(self.image, ((0, y1), (w, y2)))
    else:
        x = (((slope * x1) - y1) / slope)
        if (0 <= x <= w):
            ep.append((int(round(x)), 0))
        x = ((((slope * x1) + h) - y1) / slope)
        if (0 <= x <= w):
            ep.append((int(round(x)), h))
        y = (((- slope) * x1) + y1)
        if (0 <= y <= h):
            ep.append((0, int(round(y))))
        y = ((slope * (w - x1)) + y1)
        if (0 <= y <= h):
            ep.append((w, int(round(y))))
    ep = list(set(ep))
    ep.sort()
    return Line(self.image, ep)
