<h3 align="center">pyavatar</h3>
<p align="center">Create default user avatars from a given string</p>
<p align="center">
<img src="https://raw.githubusercontent.com/smallwat3r/pyavatar/master/ext/1.png" />
<img src="https://raw.githubusercontent.com/smallwat3r/pyavatar/master/ext/2.png" />
<img src="https://raw.githubusercontent.com/smallwat3r/pyavatar/master/ext/3.png" />
</p>
<p align="center">
<a href="https://codecov.io/gh/smallwat3r/pyavatar" rel="nofollow"><img src="https://codecov.io/gh/smallwat3r/pyavatar/branch/master/graph/badge.svg" style="max-width:100%;"></a>
<a href="https://pypi.org/project/pyavatar" rel="nofollow"><img src="https://img.shields.io/pypi/wheel/pyavatar.svg" style="max-width:100%;"></a>
<a href="https://github.com/smallwat3r/pyavatar/blob/master/LICENSE" rel="nofollow"><img src="https://img.shields.io/badge/License-MIT-green.svg" style="max-width:100%;"></a>
</p>
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
```python
>>> 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
```python
>>> 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
```python
>>> 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
```html
<img src="{{ image }}" alt="My avatar" />
```
Or save it as a bytes array
```python
>>> 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
```python
>>> 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](https://github.com/google/yapf) to format the code
```
make yapf
```
#### Release to Pypi
```
make release
```
Raw data
{
"_id": null,
"home_page": "https://github.com/smallwat3r/pyavatar",
"name": "pyavatar",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "avatar",
"author": "Matthieu Petiteau",
"author_email": "mpetiteau.pro@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/6f/ad/351563de2d3749e3419cedb13659a3e466f716fe7c4698e44be8c6f3595f/pyavatar-0.1.7.tar.gz",
"platform": null,
"description": "<h3 align=\"center\">pyavatar</h3>\n<p align=\"center\">Create default user avatars from a given string</p>\n\n<p align=\"center\">\n <img src=\"https://raw.githubusercontent.com/smallwat3r/pyavatar/master/ext/1.png\" />\n <img src=\"https://raw.githubusercontent.com/smallwat3r/pyavatar/master/ext/2.png\" />\n <img src=\"https://raw.githubusercontent.com/smallwat3r/pyavatar/master/ext/3.png\" />\n</p>\n\n<p align=\"center\">\n <a href=\"https://codecov.io/gh/smallwat3r/pyavatar\" rel=\"nofollow\"><img src=\"https://codecov.io/gh/smallwat3r/pyavatar/branch/master/graph/badge.svg\" style=\"max-width:100%;\"></a>\n <a href=\"https://pypi.org/project/pyavatar\" rel=\"nofollow\"><img src=\"https://img.shields.io/pypi/wheel/pyavatar.svg\" style=\"max-width:100%;\"></a>\n <a href=\"https://github.com/smallwat3r/pyavatar/blob/master/LICENSE\" rel=\"nofollow\"><img src=\"https://img.shields.io/badge/License-MIT-green.svg\" style=\"max-width:100%;\"></a>\n</p>\n\nThis package creates simple user avatars that can be used in web-applications. \nAvatars are generated from the first letter of a given string input. \n\n### Installation\n\nPyavatar is on Pypi so all you need is:\n```\npip install pyavatar\n```\n\n### Usage\n\nGenerate an avatar \n```python\n>>> from pyavatar import PyAvatar\n>>>\n>>> avatar = PyAvatar(\"smallwat3r\", size=250) # use a specific size\n>>> avatar = PyAvatar(\"smallwat3r\", capitalize=False) # without capitalization\n>>> avatar = PyAvatar(\"smallwat3r\", color=(40, 176, 200)) # use a specific color\n>>> avatar = PyAvatar(\"smallwat3r\", fontpath=\"/Users/me/fonts/myfont.ttf\") # use a specific font\n```\n\nChange the avatar color\n```python\n>>> avatar.color\n(191, 91, 81)\n>>> avatar.change_color() # random color\n>>> avatar.color\n(203, 22, 126) \n>>> avatar.change_color(\"#28b0c8\") # using an hex color code\n>>> avatar.color\n'#28b0c8'\n```\n\nSave the avatar as a base64 image\n```python\n>>> image = avatar.base64_image(\"jpeg\")\n'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBg ...'\n```\n\nYou can then render it in an html tag with Jinja or another template engine\n```html\n<img src=\"{{ image }}\" alt=\"My avatar\" />\n```\n\nOr save it as a bytes array\n```python\n>>> avatar.stream(\"png\")\nb'\\x89PNG\\r\\n\\x1a\\n\\x00\\x00\\x00\\rIHDR\\x00\\x00\\x00\\xfa\\x00\\x00 ...'\n```\n\nOr save it as a file locally\n```python\n>>> import os\n>>> avatar.save(f\"{os.getcwd()}/me.png\")\n```\n\n### Development\n\n#### Requirements\n\nMake sure you're using a version of Python >= 3.10\n\n- Create a virtual environment and install the dependencies\n ```\n make venv deps\n ```\n\n#### Sanity checks\n\n- Unit tests\n ```\n make tests\n ```\n\n- Mypy \n ```\n make mypy\n ```\n\n- Ruff \n ```\n make ruff\n ```\n\n- Run all the above\n ```\n make ci\n ```\n\n#### Code formatting\n\n We're using [YAPF](https://github.com/google/yapf) to format the code\n```\nmake yapf\n```\n\n#### Release to Pypi\n\n```\nmake release\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Generate simple user avatars from an input string.",
"version": "0.1.7",
"project_urls": {
"Homepage": "https://github.com/smallwat3r/pyavatar"
},
"split_keywords": [
"avatar"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4bd8c26f8ca2aac495ac50658ec25a53708c5fb3c40fc488832a46e752363e75",
"md5": "47caa32a85284e37307c1de24860cfe7",
"sha256": "346a837fd56b55040de4229f4b852f062d6f7fffa19b851d46c4b0b3e320a23c"
},
"downloads": -1,
"filename": "pyavatar-0.1.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "47caa32a85284e37307c1de24860cfe7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 68445,
"upload_time": "2024-11-04T18:24:00",
"upload_time_iso_8601": "2024-11-04T18:24:00.261484Z",
"url": "https://files.pythonhosted.org/packages/4b/d8/c26f8ca2aac495ac50658ec25a53708c5fb3c40fc488832a46e752363e75/pyavatar-0.1.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6fad351563de2d3749e3419cedb13659a3e466f716fe7c4698e44be8c6f3595f",
"md5": "0d81dfe35eff42bab2264dfc07205f06",
"sha256": "2c34c8dd8bfcb2307b8c35e29e40a0c73593b5c7fe3d661a5eb31628c22241e1"
},
"downloads": -1,
"filename": "pyavatar-0.1.7.tar.gz",
"has_sig": false,
"md5_digest": "0d81dfe35eff42bab2264dfc07205f06",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 71981,
"upload_time": "2024-11-04T18:24:02",
"upload_time_iso_8601": "2024-11-04T18:24:02.419725Z",
"url": "https://files.pythonhosted.org/packages/6f/ad/351563de2d3749e3419cedb13659a3e466f716fe7c4698e44be8c6f3595f/pyavatar-0.1.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-04 18:24:02",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "smallwat3r",
"github_project": "pyavatar",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "pyavatar"
}