Dicebear is an API wrapper for https://dicebear.com. Using this wrapper you can get custom avatars for your program.
Installing
pipinstall-Udicebear
or
python-mpipinstall-Udicebear
Make your first avatar
Here's a quick example on how to quickly make your first own avatar.
import PIL.Imageimport osfrom dicebear import DAvatar, DStyle, DOptions, DColor, DFormat, bulk_create# Enable anonymous usage statisticsos.environ['ENABLE_PYTHON_DICEBEAR_USAGE_STATS']='true'# Creating optionsoptions =DOptions( backgroundColor=DColor("00ddd0"), rotate=90)# Making a DAvatar objectav =DAvatar( style=DStyle.pixel_art, seed="John Apple", options=options)print(av.url_svg)# Prints the svg url# Editing the DAvatar objectav.edit( extra_options=DOptions(backgroundColor=DColor("000000")))# Using `extra_options` keep the `rotate` option but override the `backgroundColor` optionprint(av.url_webp)# Prints the webp url# Editing the style specific customisationsav.customise( blank_options={"face": "variant04" })# Using `blank_options` will delete your previous customisations for this DAvatar and generate new onesprint(av.url_png)# Prints the png url# Saving an avatar to your deviceav.save( location=None, # Passing `None` will save it in the current working directory file_name="dicebear_avatar", file_format=DFormat.svg, overwrite=True, open_after_save=False)# Converting the DAvatar object into a PIL.Image.Image objectav_img: PIL.Image.Image = av.pillow()# Opening and viewing the DAvatar imageav.open(use_pil=True)# or av.view()# Creating multiple random avatars of the same style at onceavatars:list=bulk_create(style=DStyle.random(), amount=10)