Giter Site home page Giter Site logo

ibonn / python_avatars Goto Github PK

View Code? Open in Web Editor NEW
63.0 1.0 13.0 7.73 MB

Avatar generation package for Python

Home Page: https://pypi.org/project/python-avatars

License: MIT License

Python 100.00%
avatar avatar-generator python svg open-source customizable avataaars mit-license avatar-generation python-avatars library package

python_avatars's Introduction

python_avatars

Codacy Badge Code Climate maintainability PyPi version PyPI - Downloads GitHub top language

Randomly generated avatars. (View at: https://github.com/ibonn/python_avatars/blob/main/examples/random_gif_apng/avatars.png)

Avatar library in Python

Table of contents

  1. Features
  2. Install
  3. Usage
  4. License
  5. Acknowledgments

Features

  • Highly customizable. Design your own clothes, hair styles, eyes... and add them to the library copying the svg files into a directory
  • Vanilla Python. No external libraries needed
  • The library contains some colors for clothes, hair and skin and supports user defined colors using hex encoding
  • Pure SVG
  • Random avatar generation

Install

Using pip, from PyPi (latest stable release):

pip install python-avatars

Using pip, from this repository (May not be stable!):

git clone https://github.com/ibonn/python_avatars.git python_avatars
cd python_avatars
pip install -e .

Usage

Create your own avatar

import python_avatars as pa

my_avatar = pa.Avatar(
    style=pa.AvatarStyle.CIRCLE,
    background_color=pa.BackgroundColor.BLACK,
    top=pa.HairType.STRAIGHT_2,
    eyebrows=pa.EyebrowType.DEFAULT_NATURAL,
    eyes=pa.EyeType.DEFAULT,
    nose=pa.NoseType.DEFAULT,
    mouth=pa.MouthType.EATING,
    facial_hair=pa.FacialHairType.NONE,
    # You can use hex colors on any color attribute...
    skin_color="#00FFFF",
    # Or you can use the colors provided by the library
    hair_color=pa.HairColor.BLACK,
    accessory=pa.AccessoryType.NONE,
    clothing=pa.ClothingType.HOODIE,
    clothing_color=pa.ClothingColor.HEATHER
)

# Save to a file
my_avatar.render("my_avatar.svg")

Create a random avatar

import python_avatars as pa

# Completely random avatar
random_avatar_1 = pa.Avatar.random()

# Completely random avatar except for the hat
random_avatar_2 = pa.Avatar.random(top=pa.HatType.HAT)  # More attributes can stay fixed

# Fixed avatar but random clothes
random_avatar_3 = pa.Avatar(
    style=pa.AvatarStyle.CIRCLE,
    hair_color=pa.HairColor.BLACK,
    accessory=pa.AccessoryType.NONE,
    clothing=pa.ClothingType.pick_random(), # The clothes are chosen randomly
)

Custom shirt text

When using the graphic shirt, - ClothingType.GRAPHIC - you can set a custom text if you want to.

import python_avatars as pa

pa.Avatar(
    style=pa.AvatarStyle.CIRCLE,
    background_color='#FF00FF',
    # Choose graphic shirt
    clothing=pa.ClothingType.GRAPHIC_SHIRT,
    clothing_color=pa.ClothingColor.GRAY_02,
    # Important to choose this as shirt_graphic, otherwise shirt_text will be ignored
    shirt_graphic=pa.ClothingGraphic.CUSTOM_TEXT,
    shirt_text='Chess'
).render("avatar_text.svg")

will output the file avatar_text.svg:

Avatar wearing shirt with custom text. (View at: https://github.com/ibonn/python_avatars/blob/main/examples/shirt_text/avatar_text.svg)

Expand the library

Suppose you have a file called suit.svg that looks like this

Suit ready to be used by the avatar. (View at: https://github.com/ibonn/python_avatars/blob/main/examples/install/suit.svg)

You can add it to the library just by running

from python_avatars import install_part

# Install the new part
install_part("suit.svg", pa.ClothingType)

And then use it

suit_avatar = pa.Avatar.random(
    clothing=pa.ClothingType.SUIT
)

suit_avatar.render("suit_avatar.svg")

Which outputs the file suit_avatar.svg that looks like this

Randomly generated avatar wearing the installed suit. (View at: https://github.com/ibonn/python_avatars/blob/main/examples/install/avatar_suit.svg)

The name of the newly added value will be exactly the name of the svg file converted to uppercase replacing all non alphanumeric chars with underscores and removing all leading digits.

Uninstalling the installed part is as easy as installing it

from python_avatars import uninstall_part, ClothingType

uninstall_part(ClothingType.SUIT, confirm=False)    # confirm=False will not prompt for confirmation

License

This project is licensed under the MIT License - see the LICENSE file for details

Acknowledgments

python_avatars's People

Contributors

ibonn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

python_avatars's Issues

Persistent avatar generation from input string

Is your feature request related to a problem? Please describe.

For example I want to add default avatar from username and it should be consistent when generated twice.

Describe the solution you'd like

username = "chiliec"
stableAvatar = pa.Avatar.random(from=username)

custom text alignment middle by default

hey, great library. felt robust enough with those installations things.

ok so in custom text the text is not aligned in the middle by default. it's slightly on the right.
image

library doesn't update while the script is running

well, for script.1.py having this updating code which is running 24/7. and let's say script.2.py which is not running.
when script1 update the library for 1 time and resting, if i run script2 to check if the library is updated, yes it is updated
after the delay script1 will check if the library is updated, no it is not.
script2 can access the updated library while the script1 is constantly using previous library. if i stop script1, and run script1 again, it will use the updated library
script1:

import python_avatars as pa
from importlib import reload
from time import sleep

while True:
  pa.install_part("suit.svg", pa.ClothingType)
  sleep(10)
  reload(pa)
  pa.uninstall_part(pa.ClothingType.SUIT)

script2:

try:
  getattr(pa.ClothignType, "SUIT")
  print("found")
except:
  print("doesn't exist")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.