def s2i(jsonsig, input_image=BLANK_IMAGE, pincolor=(0,0,255),
        force_no_sig_image=False, nosig_image=NO_SIG_IMAGE):
    
      
    if force_no_sig_image==True:
        im = Image.open(nosig_image)
        return im
    #Decode valid json or return None
    try:
        l=json.loads(jsonsig)
    except(exceptions.ValueError):
        im = Image.open(nosig_image)
        return im
    #Make sure its a signature or return None
    if not l[0].has_key('lx') or not l[0].has_key('my'):
        im = Image.open(nosig_image)
        return im
    #create a blank image from out template
    im = Image.open(input_image)
    #create a drawing object
    draw = ImageDraw.Draw(im)
    #iterate over our list of points and draw corresponding lines
    for i in l:
        draw.line((i['lx'], i['ly'], i['mx'], i['my']), fill=pincolor, width=1)
    #delete our draw object (cleanup and free the memory)
    del draw 
    
    # save image
    #im.save(output_image, "PNG")
    return im
def s2if(jsonsig, output_image="signature.png", input_image=BLANK_IMAGE,
            pincolor=(0,0,255)):
    #Decode valid json or return None
    try:
        l=json.loads(jsonsig)
    except(exceptions.ValueError):
        return None
    #Make sure its a signature or return None
    if not l[0].has_key('lx') or not l[0].has_key('my'):
        return None
    #create a blank image from out template
    im = Image.open(input_image)
    #create a drawing object
    draw = ImageDraw.Draw(im)
    #iterate over our list of points and draw corresponding lines
    for i in l:
        draw.line((i['lx'], i['ly'], i['mx'], i['my']), fill=pincolor, width=1)
    #delete our draw object (cleanup and free the memory)
    del draw 

    # save image
    im.save(output_image, "PNG")
    #get its path
    BASE_DIR = os.path.dirname(os.path.abspath(output_image))
    IMAGE_PATH = os.path.join(BASE_DIR, output_image)
    return IMAGE_PATH