'usage:  i = Identicon(\'xx\')
print(i.base64())
return: this image\'s base64 code
created by: liuzheng712
bug report: https://github.com/liuzheng712/identicons/issues'

def base64(self, format='PNG'):

    self.calculate()
    fp = StringIO()
    self.image.encoderinfo = {}
    self.image.encoderconfig = ()
    if (format.upper() not in Image.SAVE):
        Image.init()
    save_handler = Image.SAVE[format.upper()]
    try:
        save_handler(self.image, fp, '')
    finally:
        fp.seek(0)
        return 'data:image/png;base64,{0}'.format(base64.b64encode(fp.read()))
