Skip to main content

Pilmoji is a fast and reliable emoji renderer for PIL.

Project description

Pilmoji

Pilmoji is an emoji renderer for Pillow, Python's imaging library.
It supports not only unicode emojis, but also Discord emojis.

Pilmoji uses twemoji for unicode emojis.
For Discord emojis, Pilmoji will send a request to Discord's CDN.
Everything is cached, to ensure fast results.

You can also use Microsoft's emojis instead of Twemoji, if that's what you prefer.

Features

  • Asynchronous support
  • Multi-line support
  • Discord emoji support
  • Emoji position and size adjusting
  • Twemoji and Microsoft emoji support
  • Caching

Asynchronous Support

Pilmoji has both synchronous (requests) and asynchrounous (aiohttp) support.

Installation

Pilmoji should be installed using pip:

pip install pilmoji

Installing from Github will most likely fail.

Examples

Basic 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

Example result

Async usage

import asyncio
from pilmoji import AsyncPilmoji
from PIL import Image, ImageFont

my_string = '''
Hello, world! 👋 Here are some emojis: 🎨 🌊 😎
I also support Discord emoji: <:rooThink:596576798351949847>
'''


async def main():
    with Image.new('RGB', (550, 80), (255, 255, 255)) as image:
        font = ImageFont.truetype('arial.ttf', 24)

        async with AsyncPilmoji(image) as pilmoji:
            await pilmoji.text((10, 10), my_string.strip(), (0, 0, 0), font)

        image.show()


asyncio.run(main())

Results are the exact same.

Size/position adjustments

Is an emoji too low, or too small for a given font?
You can also render emojis with offsets:

pilmoji.text((10, 10), my_string.strip(), (0, 0, 0), font,
             emoji_size_factor=1.15, emoji_position_offset=(0, -2))

Using Microsoft emojis

Pilmoji also supports Microsoft emojis.
Simply set the use_microsoft_emoji kwarg to True, as such:

with Pilmoji(image, use_microsoft_emoji=True) as pilmoji:
    ...

results

Notes

  • [async] If you're running PIL in an executor, use the sync version of Pilmoji instead.
  • [async] It is not recommended to run PIL in asynchronous conditions (PIL is blocking.)
    • If you really have to, run the manipulation in an executor.

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

pilmoji_fixed-1.3.2.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pilmoji_fixed-1.3.2-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file pilmoji_fixed-1.3.2.tar.gz.

File metadata

  • Download URL: pilmoji_fixed-1.3.2.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.2

File hashes

Hashes for pilmoji_fixed-1.3.2.tar.gz
Algorithm Hash digest
SHA256 4bee1acad74d152fe37eb7b8ba14b208a458e192b47f41b3ce26275f277327bc
MD5 df1fbe8498a6e5edf3f7f4beb14dda42
BLAKE2b-256 45bbb1b5a478674dec89ebc106448587082fa2cadf68b4311878f7a445a09fc1

See more details on using hashes here.

File details

Details for the file pilmoji_fixed-1.3.2-py3-none-any.whl.

File metadata

  • Download URL: pilmoji_fixed-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.2

File hashes

Hashes for pilmoji_fixed-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 233fa5e097994c55b7e1bc408fc9ea6d3dbcf65ba7fd31e3de1e350b837a7a49
MD5 0e964ac9cb6a66d5977f162e3a1194d0
BLAKE2b-256 ea39a844f7bde2fbee0decf8daf6b2f05867097785fa40a807980b6758a92c80

See more details on using hashes here.

Supported by

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