def embed64(filename=None, file=None, data=None, extension='image/gif'):
 if (filename and os.path.exists(file)):
  fp = open(filename, 'rb')
  data = fp.read()
  fp.close()
 data = base64.b64encode(data)
 return ('data:%s;base64,%s' % (extension, data))

def embed64 ( filename = None , file = None , data = None , extension = 'image/gif' ) : if ( filename and os . path . exists ( file ) ) : fp = open ( filename , 'rb' ) data = fp . read ( ) fp . close ( ) data = base64 . b64encode ( data ) return ( 'data:%s;base64,%s' % ( extension , data ) )
helper to encode the provided data into base64 .