Package: pioupiou
PiouPiouAn avatar generator optimised for generating random avatars based on multiple image layers, able to return same image from a string "seed".
Heavily inspired byDavid Revoy'scat avatar generatorandMonsterID by Andreas Gohr's.This generator relies on the Pillow library to do image processing.See aDemo(runningpioupiouweb from buxx).InstallFrom pypi$pipinstallpioupiouFrom sourceclone this repositorypip install -e "."UsageHigh Level ApiThe high level Api will help you choose avatar between multiples themes, according to installed themes.frompioupiouimportAvatarGenerator# check sample/example.py for code to build default sample themesfromsample.exampleimportgenerate_default_themesthemes=generate_default_themes(sample_dir_path="./sample")avatar_generator=AvatarGenerator(themes)# note: you can override default theme list and/or theme chooser (mecanism to randomly choose a theme according to token)avatar=avatar_generator.generate_avatar(token="just a random string")avatar_generator.save_on_disk(avatar,path="/tmp/saved_file.png")# note: you can choose a specific theme according to activate themeavatar=avatar_generator.generate_avatar(theme_name="cat_revoy",token="just a random string")avatar_generator.save_on_disk(avatar,path="/tmp/saved_file_2.png")Low Level Api (AvatarTheme)The easy way to use it is to be based on FolderAvatarTheme. To do this, you should create many .png file of same image, all
with transparency. You should follow a similar naming pattern as in the following example.To test it, you can, for instance, use a cat avatarby David Revoy:frompioupiouimportFolderAvatarThemetheme=FolderAvatarTheme(folder_path="sample/cat_revoy",layers_name=["body","fur","eyes","mouth","accessorie"],)avatar=theme.generate_avatar(token="just a random string")theme.save_on_disk(avatar,path="/tmp/saved_file.png")Or a bird avatarby David Revoy:frompioupiouimportFolderAvatarThemetheme=FolderAvatarTheme("sample/bird_revoy",layers_name=["tail","hoop","body","wing","eyes","bec","accessorie"],)avatar=theme.generate_avatar(token="just a random string")theme.save_on_disk(avatar,path="/tmp/saved_file.png")Or a Monster avatarby Andreas Gohr's:frompioupiouimportFolderAvatarThemetheme=FolderAvatarTheme("sample/monster_id",layers_name=["legs","hair","arms","body","eyes","mouth"],)avatar=theme.generate_avatar(token="just a random string")theme.save_on_disk(avatar,path="/tmp/saved_file.png")Configure ChooserTo generate avatars, pioupiou provides tools to help you use the algorithm you want.
The default behaviour is to rely onrandom.Random(), but pioupiou is made to support any type of chooser.
To do this, you just need to configure the chooser with yourAvatarTheme:frompioupiouimportFolderAvatarThemefromrandomimportRandomtheme=FolderAvatarTheme(folder_path="sample/cat_revoy",layers_name=["body","fur","eyes","mouth","accessorie"],chooser=Random(),# same as default, don't change anything)You can use any hashlib algorithm you want fromhashlib, usingpioupiou.chooser.HashLibChooser.
It will make choices using a modulo.frompioupiouimportFolderAvatarThemeimporthashlibfrompioupiou.chooserimportHashLibChoosertheme=FolderAvatarTheme(folder_path="sample/cat_revoy",layers_name=["body","fur","eyes","mouth","accessorie"],chooser=HashLibChooser(hashlib.sha256()),# hashlib.sha256() is just an example, hashlib.md5() should also work for example.)You can also implementpioupiou.chooser.Chooserand use a custom chooser.