Skip to content

Commit bc60cda

Browse files
committed
Version 2.0
1 parent e12acfc commit bc60cda

File tree

20 files changed

+994
-594
lines changed

20 files changed

+994
-594
lines changed

.gitignore

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### VirtualEnv template
3+
# Virtualenv
4+
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
5+
.Python
6+
[Bb]in
7+
[Ii]nclude
8+
[Ll]ib
9+
[Ll]ib64
10+
[Ll]ocal
11+
[Ss]cripts
12+
pyvenv.cfg
13+
.venv
14+
pip-selfcheck.json
15+
16+
### Python template
17+
# Byte-compiled / optimized / DLL files
18+
__pycache__/
19+
*.py[cod]
20+
*$py.class
21+
22+
# C extensions
23+
*.so
24+
25+
# Distribution / packaging
26+
.Python
27+
build/
28+
develop-eggs/
29+
dist/
30+
downloads/
31+
eggs/
32+
.eggs/
33+
lib/
34+
lib64/
35+
parts/
36+
sdist/
37+
var/
38+
wheels/
39+
pip-wheel-metadata/
40+
share/python-wheels/
41+
*.egg-info/
42+
.installed.cfg
43+
*.egg
44+
MANIFEST
45+
46+
# PyInstaller
47+
# Usually these files are written by a python script from a template
48+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
49+
*.manifest
50+
*.spec
51+
52+
# Installer logs
53+
pip-log.txt
54+
pip-delete-this-directory.txt
55+
56+
# Unit test / coverage reports
57+
htmlcov/
58+
.tox/
59+
.nox/
60+
.coverage
61+
.coverage.*
62+
.cache
63+
nosetests.xml
64+
coverage.xml
65+
*.cover
66+
*.py,cover
67+
.hypothesis/
68+
.pytest_cache/
69+
cover/
70+
71+
# Translations
72+
*.mo
73+
*.pot
74+
75+
# Django stuff:
76+
*.log
77+
local_settings.py
78+
db.sqlite3
79+
db.sqlite3-journal
80+
81+
# Flask stuff:
82+
instance/
83+
.webassets-cache
84+
85+
# Scrapy stuff:
86+
.scrapy
87+
88+
# Sphinx documentation
89+
docs/_build/
90+
91+
# PyBuilder
92+
.pybuilder/
93+
target/
94+
95+
# Jupyter Notebook
96+
.ipynb_checkpoints
97+
98+
# IPython
99+
profile_default/
100+
ipython_config.py
101+
102+
# pyenv
103+
# For a library or package, you might want to ignore these files since the code is
104+
# intended to run in multiple environments; otherwise, check them in:
105+
# .python-version
106+
107+
# pipenv
108+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
109+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
110+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
111+
# install all needed dependencies.
112+
#Pipfile.lock
113+
114+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
115+
__pypackages__/
116+
117+
# Celery stuff
118+
celerybeat-schedule
119+
celerybeat.pid
120+
121+
# SageMath parsed files
122+
*.sage.py
123+
124+
# Environments
125+
.env
126+
.venv
127+
env/
128+
venv/
129+
ENV/
130+
env.bak/
131+
venv.bak/
132+
133+
# Spyder project settings
134+
.spyderproject
135+
.spyproject
136+
137+
# Rope project settings
138+
.ropeproject
139+
140+
# mkdocs documentation
141+
/site
142+
143+
# mypy
144+
.mypy_cache/
145+
.dmypy.json
146+
dmypy.json
147+
148+
# Pyre type checker
149+
.pyre/
150+
151+
# pytype static type analyzer
152+
.pytype/
153+
154+
# Cython debug symbols
155+
cython_debug/
156+

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2021-present jay3332
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 48 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
# Pilmoji
2-
Pilmoji is an emoji renderer for Pillow, Python's imaging library.
3-
It supports not only unicode emojis, but also Discord emojis.
2+
Pilmoji is an emoji renderer for [Pillow](https://github.com/python-pillow/Pillow/),
3+
Python's imaging library.
44

5-
Pilmoji uses [twemoji](https://github.com/twitter/twemoji) for unicode emojis.
6-
For Discord emojis, Pilmoji will send a request to Discord's CDN.
7-
Everything is cached, to ensure fast results.
8-
9-
You can also use Microsoft's emojis instead of Twemoji, if that's what you prefer.
5+
Pilmoji comes equipped with support for both unicode emojis and Discord emojis.
106

117
## Features
12-
- Asynchronous support
13-
- Multi-line support
148
- Discord emoji support
15-
- Emoji position and size adjusting
16-
- Twemoji __and__ Microsoft emoji support
17-
- Caching
18-
19-
## Asynchronous Support
20-
Pilmoji has both synchronous ([requests](https://pypi.org/project/requests/))
21-
and asynchrounous ([aiohttp](https://pypi.org/project/aiohttp/)) support.
22-
23-
## Installation
24-
Pilmoji should be installed using `pip`:
25-
```
26-
pip install pilmoji
9+
- Multi-line rendering support
10+
- Emoji position and/or size adjusting
11+
- Many built-in emoji sources
12+
- Optional caching
13+
14+
## Installation and Requirements
15+
You must have Python 3.8 or higher in order to install Pilmoji.
16+
17+
Installation can be done with `pip`:
18+
```shell
19+
$ pip install -U pilmoji
2720
```
28-
Installing from Github will most likely fail.
2921

30-
## Examples
31-
### Basic usage
22+
Optionally, you can add the `[requests]` option to install requests
23+
alongside Pilmoji:
24+
```shell
25+
$ pip install -U pilmoji[requests]
26+
```
27+
28+
The option is not required, instead if `requests` is not installed,
29+
Pilmoji will fallback to use the builtin `urllib`.
30+
31+
You may also install from Github.
32+
33+
## Usage
3234
```py
3335
from pilmoji import Pilmoji
3436
from PIL import Image, ImageFont
@@ -47,49 +49,37 @@ with Image.new('RGB', (550, 80), (255, 255, 255)) as image:
4749

4850
image.show()
4951
```
52+
5053
#### Result
5154
![Example result](https://jay.has-no-bra.in/f/j4iEcc.png)
52-
### Async usage
53-
```py
54-
import asyncio
55-
from pilmoji import AsyncPilmoji
56-
from PIL import Image, ImageFont
5755

58-
my_string = '''
59-
Hello, world! 👋 Here are some emojis: 🎨 🌊 😎
60-
I also support Discord emoji: <:rooThink:596576798351949847>
61-
'''
56+
## Switching emoji sources
57+
As seen from the example, Pilmoji defaults to the `Twemoji` emoji source.
6258

59+
If you prefer emojis from a different source, for example Microsoft, simply
60+
set the `source` kwarg in the constructor to a source found in the
61+
`pilmoji.source` module:
6362

64-
async def main():
65-
with Image.new('RGB', (550, 80), (255, 255, 255)) as image:
66-
font = ImageFont.truetype('arial.ttf', 24)
63+
```py
64+
from pilmoji.source import MicrosoftEmojiSource
6765

68-
async with AsyncPilmoji(image) as pilmoji:
69-
await pilmoji.text((10, 10), my_string.strip(), (0, 0, 0), font)
66+
with Pilmoji(image, source=MicrosoftEmojiSource) as pilmoji:
67+
...
68+
```
7069

71-
image.show()
70+
![results](https://jay.has-no-bra.in/f/suPfj0.png)
7271

72+
It is also possible to create your own emoji sources via subclass.
73+
74+
## Fine adjustments
75+
If an emoji looks too small or too big, or out of place, you can make fine adjustments
76+
with the `emoji_scale_factor` and `emoji_position_offset` kwargs:
7377

74-
asyncio.run(main())
75-
```
76-
Results are the exact same.
77-
### Size/position adjustments
78-
Is an emoji too low, or too small for a given font?
79-
You can also render emojis with offsets:
8078
```py
8179
pilmoji.text((10, 10), my_string.strip(), (0, 0, 0), font,
82-
emoji_size_factor=1.15, emoji_position_offset=(0, -2))
83-
```
84-
### Using Microsoft emojis
85-
Pilmoji also supports Microsoft emojis.
86-
Simply set the `use_microsoft_emoji` kwarg to True, as such:
87-
```py
88-
with Pilmoji(image, use_microsoft_emoji=True) as pilmoji:
89-
...
80+
emoji_scale_factor=1.15, emoji_position_offset=(0, -2))
9081
```
91-
![results](https://jay.has-no-bra.in/f/suPfj0.png)
92-
## Notes
93-
- [async] If you're running PIL in an executor, use the **sync** version of Pilmoji instead.
94-
- [async] It is not recommended to run PIL in asynchronous conditions (PIL is blocking.)
95-
- If you really have to, run the manipulation in an executor.
82+
83+
## Contributing
84+
Contributions are welcome. Make sure to follow [PEP-8](https://www.python.org/dev/peps/pep-0008/)
85+
styling guidelines.

pilmoji/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
# sync
2-
from .sync import Pilmoji, Requester
1+
from . import helpers, source
2+
from .core import Pilmoji
3+
from .helpers import *
34

4-
# async
5-
from .aio import AsyncPilmoji, AsyncRequester
6-
7-
8-
__version__ = '1.3.2'
5+
__version__ = '2.0.0'
96
__author__ = 'jay3332'

pilmoji/aio/__init__.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)