'clamp all values between zero and the image width'

def _clamp(self, x, y):

    rx = x
    ry = y
    if (x > self.imgw):
        rx = self.imgw
    if (x < 0):
        rx = 0
    if (y > self.imgh):
        ry = self.imgh
    if (y < 0):
        ry = 0
    return (rx, ry)
