Generate simple user avatars from an input string.
Project description
pyavatar
Create default user avatars from a given string
This package creates simple user avatars that can be used in web-applications.
Avatars are generated from the first letter of a given string input.
Installation
Pyavatar is on Pypi so all you need is:
pip install pyavatar
Usage
Generate an avatar
>>> from pyavatar import PyAvatar
>>>
>>> avatar = PyAvatar("smallwat3r", size=250) # use a specific size
>>> avatar = PyAvatar("smallwat3r", capitalize=False) # without capitalization
>>> avatar = PyAvatar("smallwat3r", color=(40, 176, 200)) # use a specific color
>>> avatar = PyAvatar("smallwat3r", fontpath="/Users/me/fonts/myfont.ttf") # use a specific font
Change the avatar color
>>> avatar.color
(191, 91, 81)
>>> avatar.change_color() # random color
>>> avatar.color
(203, 22, 126)
>>> avatar.change_color("#28b0c8") # using an hex color code
>>> avatar.color
'#28b0c8'
Save the avatar as a base64 image
>>> image = avatar.base64_image("jpeg")
'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBg ...'
You can then render it in an html tag with Jinja or another template engine
<img src="{{ image }}" alt="My avatar" />
Or save it as a bytes array
>>> avatar.stream("png")
b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\xfa\x00\x00 ...'
Or save it as a file locally
>>> import os
>>> avatar.save(f"{os.getcwd()}/me.png")
Development
Requirements
Make sure you're using a version of Python >= 3.10
- Create a virtual environment and install the dependencies
make venv deps
Sanity checks
-
Unit tests
make tests -
Mypy
make mypy -
Ruff
make ruff -
Run all the above
make ci
Code formatting
We're using YAPF to format the code
make yapf
Release to Pypi
make release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyavatar-0.1.8.tar.gz.
File metadata
- Download URL: pyavatar-0.1.8.tar.gz
- Upload date:
- Size: 73.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
061df5eba2e71e2c6a6d2dbb0d7229ae46b16b79c8c8fa9ee7ef7badf776c625
|
|
| MD5 |
b4da385c613ecf3b0c6aa8ad8c0c946f
|
|
| BLAKE2b-256 |
3f69eee3ceb12a7c879a881db621977da467fe71539a87536b1bdef9398e777f
|
File details
Details for the file pyavatar-0.1.8-py3-none-any.whl.
File metadata
- Download URL: pyavatar-0.1.8-py3-none-any.whl
- Upload date:
- Size: 70.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32c4a0e54e7229eec96f118e61cd84f5698510c7df3b475b1f42e9c57328f9d1
|
|
| MD5 |
15e5ac45a4c38cf155aa136d7b6e95af
|
|
| BLAKE2b-256 |
eed3f5ca03e1fdcbad555b986c2fbdcac6799f32a826a67adac4de564307ac5c
|