AvatarMaker is a Python library for generating customizable avatars. It's based on the py-avataaars project and provides an easy way to create both random and specific avatars.
To install AvatarMaker, you can use pip:
pip3 -r requirements.txt
Here's how to use the AvatarMaker:
from py_avataaars import AvatarMaker as am
This returns a tuple containing the SVG string of the avatar and an AvatarInfo object with the avatar's attributes.\n Safe avatar are better suited for proffesionel use.
avatar_svg, avatar_info = am.create_random_avatar()
avatar_svg, avatar_info = am.create_random_avatar_safe()
This returns a list of 25 tuples, each containing an SVG string and an AvatarInfo object.
avatars = am.create_n_random_avatar_safe(25)
for avatar_svg, avatar_info in avatars:
print(avatar_info.json())
print(avatar_info.info_str()) # Detailed info
print(avatar_info.info_str_short()) # Short info
print(avatar_info.make_id()) # can use this id to remake avatar , ligther to save in db
all_enum_values = am.get_all_enum_values()
print(all_enum_values)
This saves each avatar as an SVG file.
for i, (avatar_svg, avatar_info) in enumerate(avatars):
with open(f'{i}-{avatar_info.info_str_short()}', 'w') as f:
f.write(avatar_svg)
You can create a custom avatar by specifying values for each attribute:
from py_avataaars import AvatarMaker as am
from py_avataaars import AvatarInfo
import py_avataaars as pa
custom_avatar_info = AvatarInfo(
top_type=pa.TopType.LONG_HAIR_DREADS,
hair_color=pa.HairColor.BROWN_DARK,
eye_type=pa.EyesType.WINK,
eyebrow_type=pa.EyebrowType.DEFAULT,
mouth_type=pa.MouthType.SMILE,
)
custom_avatar_svg = am.create_avatar_from_info(custom_avatar_info)
Here's some example of "safe" avatars :
Here's some example of "unsafe" avatars , true randomnesse: