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.

Features

  • Asynchronous support
  • Multi-line support
  • Discord 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.

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-1.0.1.tar.gz (6.4 kB view details)

Uploaded Source

File details

Details for the file pilmoji-1.0.1.tar.gz.

File metadata

  • Download URL: pilmoji-1.0.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pilmoji-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b3776300288391044ba05d96b81c677311ba0f3b5237b7d562fa9d4701628799
MD5 bf0d33f9a2a2169f34bf7dba41a4653c
BLAKE2b-256 3cd2741d9241b11a173ff1fc4de232514f82ed8fb2de1f8c78658dcab3b31742

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