Skip to content
forked from kebu/py-avataaars

AvatarMaker: A Python library for generating customizable SVG avatars. Create random or specific avatars with ease, based on the py-avataaars project.https://github.com/kebu/py-avataaars

Notifications You must be signed in to change notification settings

Raspova/PhythonAvatarGenerator

 
 

Repository files navigation

AvatarMaker

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.

Installation

To install AvatarMaker, you can use pip:

pip3 -r requirements.txt

Usage

Here's how to use the AvatarMaker:

Importing the AvatarMaker

from py_avataaars import AvatarMaker as am

Creating a Single Random Avatar and "Safe" Random Avatar

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()

Creating Multiple Random Avatars

This returns a list of 25 tuples, each containing an SVG string and an AvatarInfo object.

avatars = am.create_n_random_avatar_safe(25)

Avatar info

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)

Customization

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)

SVG Image

Examples SAFE Avatar

Here's some example of "safe" avatars :

SVG Image SVG Image SVG Image SVG Image SVG Image SVG Image SVG Image SVG Image SVG Image SVG Image SVG Image SVG Image

Examples Avatar

Here's some example of "unsafe" avatars , true randomnesse:

SVG Image SVG Image SVG Image SVG Image SVG Image SVG Image SVG Image SVG Image SVG Image SVG Image SVG Image SVG Image

About

AvatarMaker: A Python library for generating customizable SVG avatars. Create random or specific avatars with ease, based on the py-avataaars project.https://github.com/kebu/py-avataaars

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%