def avatarGen(value): avatar = Avatar(rows=10, columns=10) image_byte_array = avatar.get_image(string=value, width=50, height=50, pad=10) avatar.save(image_byte_array=image_byte_array, save_location='static/img/' + value + '.png') return 'static/img/' + value + '.png'
def main(): # Example usage avatar = Avatar(rows=10, columns=10) image_byte_array = avatar.get_image(string='john_smith_2008', width=400, height=400, pad=10) return avatar.save(image_byte_array=image_byte_array, save_location='example.png')
def generate_avatar(user_id): """ Generate a deterministic avatar and return the avatar as a base64-encoded image """ user_seed = "%s%s" % (SECRET_KEY, user_id) # randomavatar generates random colors. Workaround this by initializing # the random number generator with the same user-specific seed every time random.seed(hash(user_seed)) avatar = Avatar(rows=8, columns=8) image = avatar.get_image(user_seed, 64, 64) image = "data:image/png;base64,%s" % str(base64.b64encode(image), "utf-8") return image
def generate_random_avatar(filename=None, n=10): if not filename: raise ValueError( 'Please set a file path where to save generated avatar') st = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(n)) avatar = Avatar(rows=13, columns=13) image_byte_array = avatar.get_image(string=st, width=89, height=89, pad=10) return avatar.save(image_byte_array=image_byte_array, save_location=filename)
def avatarGen(value): avatar = Avatar(rows=10, columns=10) image_byte_array = avatar.get_image(string=value, width=50, height=50, pad=10) avatar.save(image_byte_array=image_byte_array, save_location='static/img/'+value+'.png') return 'static/img/'+value+'.png'
def main(): # Example usage avatar = Avatar(rows=10, columns=10) image_byte_array = avatar.get_image(string="john_smith_2008", width=400, height=400, pad=10) return avatar.save(image_byte_array=image_byte_array, save_location="example.png")