Skip to main content

Generate simple user avatars from an input string.

Project description

pyavatar

Create default user avatars from a given string

This package allows the creation of 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", color=(40, 176, 200))  # use a specific color
>>> avatar = PyAvatar("smallwat3r", font="/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
>>> 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")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyavatar-0.0.2.tar.gz (71.0 kB view hashes)

Uploaded Source

Built Distribution

pyavatar-0.0.2-py3-none-any.whl (5.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page