Pilmoji is an emoji renderer for Pillow, Python's imaging library.
Project description
Pilmoji
Pilmoji is an emoji renderer for Pillow, Python's imaging library.
Pilmoji comes equipped with support for both unicode emojis and Discord emojis.
Features
- Discord emoji support
- Multi-line rendering support
- Emoji position and/or size adjusting
- Many built-in emoji sources
- Optional caching
Installation and Requirements
You must have Python 3.8 or higher in order to install Pilmoji.
Installation can be done with pip
:
$ pip install -U pilmoji
Optionally, you can add the [requests]
option to install requests
alongside Pilmoji:
$ pip install -U pilmoji[requests]
The option is not required, instead if requests
is not installed,
Pilmoji will fallback to use the builtin urllib
.
You may also install from Github.
Usage
from pilmoji import Pilmoji
from PIL import Image, ImageFont
my_string = '''
Hello, world! 👋 Here are some emojis: 🎨 🌊 😎
I also support Discord emoji: <:rooThink:596576798351949847>
'''
with Image.new('RGB', (550, 80), (255, 255, 255)) as image:
font = ImageFont.truetype('arial.ttf', 24)
with Pilmoji(image) as pilmoji:
pilmoji.text((10, 10), my_string.strip(), (0, 0, 0), font)
image.show()
Result
Switching emoji sources
As seen from the example, Pilmoji defaults to the Twemoji
emoji source.
If you prefer emojis from a different source, for example Microsoft, simply
set the source
kwarg in the constructor to a source found in the
pilmoji.source
module:
from pilmoji.source import MicrosoftEmojiSource
with Pilmoji(image, source=MicrosoftEmojiSource) as pilmoji:
...
It is also possible to create your own emoji sources via subclass.
Fine adjustments
If an emoji looks too small or too big, or out of place, you can make fine adjustments
with the emoji_scale_factor
and emoji_position_offset
kwargs:
pilmoji.text((10, 10), my_string.strip(), (0, 0, 0), font,
emoji_scale_factor=1.15, emoji_position_offset=(0, -2))
Contributing
Contributions are welcome. Make sure to follow PEP-8 styling guidelines.
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
File details
Details for the file pilmoji-2.0.4.tar.gz
.
File metadata
- Download URL: pilmoji-2.0.4.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3861c09999f36bb32dd559e181b63a8a9c8068b2cddcac32637581e48de2d11f |
|
MD5 | 47f9aa4da933c597d1dcf15f1529a88d |
|
BLAKE2b-256 | e104e463218cffa0d8e145aa3c5fb409e483134df69ccfdce02bff0e05bce08e |
File details
Details for the file pilmoji-2.0.4-py3-none-any.whl
.
File metadata
- Download URL: pilmoji-2.0.4-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fcb2116226ed8aa600fcf6e65d7693b5d08d60715f8c460553130081a5adc26 |
|
MD5 | 8082e935cbc4161752214db63b6fbfe3 |
|
BLAKE2b-256 | 477cb7139e422e460889077d34b8e668b7b61af19e303b7a66adc736313fb71a |