Pilmoji for nonebot-plugin-parser
Reason this release was yanked:
bug
Project description
Pilmoji for Parser
A simplified emoji renderer for Pillow, Python's imaging library. This is a streamlined fork optimized for use with nonebot-plugin-parser.
โจ Features
- ๐จ Unicode Emoji Support - Render standard Unicode emojis
- ๐ฌ Discord Emoji Support - Render custom Discord emojis
- ๐ Multi-line Text - Automatic line break handling
- ๐ญ Multiple Emoji Styles - Apple, Google, Twitter, Facebook
- โก Async/Await - Built with modern async Python
- ๐พ Smart Caching - Local file caching for better performance
- ๐ง Simple API - Easy-to-use interface with sensible defaults
๐ฆ Installation
Requirements: Python 3.10 or higher
pip install apilmoji
Or install from source:
git clone https://github.com/fllesser/apilmoji.git
cd apilmoji
pip install .
๐ Quick Start
Basic Usage (Unicode Emoji Only)
import asyncio
from pilmoji import Pilmoji
from PIL import Image, ImageFont
async def main():
text = '''
Hello, world! ๐
Here are some emojis: ๐จ ๐ ๐
Multi-line support! ๐ โจ
'''
# Create image
image = Image.new('RGB', (550, 150), (255, 255, 255))
font = ImageFont.truetype('arial.ttf', 24)
# Render text with emojis
async with Pilmoji() as pilmoji:
await pilmoji.text(image, (10, 10), text.strip(), font, fill=(0, 0, 0))
image.save('output.png')
image.show()
asyncio.run(main())
With Discord Emoji Support
async def main():
text = '''
Unicode emoji: ๐ ๐จ ๐
Discord emoji: <:custom:123456789012345678>
'''
image = Image.new('RGB', (550, 100), (255, 255, 255))
font = ImageFont.truetype('arial.ttf', 24)
async with Pilmoji() as pilmoji:
await pilmoji.text_with_discord_emoji(
image, (10, 10), text.strip(), font, fill=(0, 0, 0)
)
image.save('output.png')
asyncio.run(main())
๐จ Emoji Styles
Choose from different emoji styles:
from pilmoji import Pilmoji, EmojiStyle, EmojiCDNSource
# Apple style (default)
source = EmojiCDNSource(style=EmojiStyle.APPLE)
# Google style
source = EmojiCDNSource(style=EmojiStyle.GOOGLE)
# Twitter style
source = EmojiCDNSource(style=EmojiStyle.TWITTER)
# Facebook style
source = EmojiCDNSource(style=EmojiStyle.FACEBOOK)
async with Pilmoji(source=source) as pilmoji:
await pilmoji.text(image, (10, 10), "Hello ๐", font)
๐ง API Reference
Pilmoji
Main class for rendering text with emojis.
Constructor:
Pilmoji(
source: BaseSource = EmojiCDNSource(),
cache: bool = True
)
Parameters:
source: Emoji source to use (default:EmojiCDNSource())cache: Enable emoji caching (default:True)
Methods:
async text(image, xy, text, font, fill=None)
Render text with Unicode emoji support.
image: PIL Image object to render ontoxy: Tuple of (x, y) coordinates for text positiontext: Text string to render (supports multiple lines)font: PIL Font objectfill: Text color (default: black)
async text_with_discord_emoji(image, xy, text, font, fill=None)
Render text with both Unicode and Discord emoji support.
Parameters are the same as text().
EmojiCDNSource
Default emoji source using emojicdn.elk.sh.
Constructor:
EmojiCDNSource(
style: EmojiStyle = EmojiStyle.APPLE,
cache_dir: Path | None = None
)
Parameters:
style: Emoji style to use (Apple, Google, Twitter, Facebook)cache_dir: Custom cache directory (default:~/.cache/pilmoji)
๐ Custom Emoji Sources
Create your own emoji source by subclassing BaseSource:
from pilmoji import BaseSource
from io import BytesIO
class CustomEmojiSource(BaseSource):
async def get_emoji(self, emoji: str) -> BytesIO | None:
# Your custom emoji fetching logic
pass
async def get_discord_emoji(self, id: int) -> BytesIO | None:
# Your custom Discord emoji fetching logic
pass
# Use your custom source
async with Pilmoji(source=CustomEmojiSource()) as pilmoji:
await pilmoji.text(image, (10, 10), "Hello ๐", font)
๐ Examples
Different Text Colors
# Red text
await pilmoji.text(image, (10, 10), "Red text ๐ด", font, fill=(255, 0, 0))
# RGB tuple
await pilmoji.text(image, (10, 50), "Blue text ๐ต", font, fill=(0, 0, 255))
# RGBA tuple with transparency
await pilmoji.text(image, (10, 90), "Semi-transparent ๐ป", font, fill=(0, 0, 0, 128))
Multi-line Text
text = """Line 1 with emoji ๐จ
Line 2 with emoji ๐
Line 3 with emoji ๐"""
await pilmoji.text(image, (10, 10), text, font, fill=(0, 0, 0))
Without Context Manager
pilmoji = Pilmoji()
await pilmoji.text(image, (10, 10), "Hello ๐", font)
await pilmoji.aclose() # Don't forget to close!
๐งช Development
Setup
# Clone the repository
git clone https://github.com/fllesser/apilmoji.git
cd apilmoji
# Install dependencies
uv sync --dev
# Run tests
uv run pytest
# Run linting
uv run ruff check src/
Running Tests
# Run all tests
uv run poe test
# Run with coverage
uv run pytest --cov=src --cov-report=html
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Original Pilmoji project by jay3332
- Pillow - Python Imaging Library
- emojicdn.elk.sh - Emoji CDN service
๐ Links
- Repository: https://github.com/fllesser/apilmoji
- Issues: https://github.com/fllesser/apilmoji/issues
- Releases: https://github.com/fllesser/apilmoji/releases
- Related Project: nonebot-plugin-parser
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file apilmoji-0.1.0.tar.gz.
File metadata
- Download URL: apilmoji-0.1.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66685bbac4bee1427cc6b05c4ef094959b15c7b4925ed8a9fcef18f2908b8784
|
|
| MD5 |
e1a2235fd695060b99b55822966cf66a
|
|
| BLAKE2b-256 |
3173a9f2c012bc087975822928e5ced175acc72bb0ea94b50450bfda289546b3
|
File details
Details for the file apilmoji-0.1.0-py3-none-any.whl.
File metadata
- Download URL: apilmoji-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58306ebcdc994069e9c074338ff8497cf25d0cfd67216be06e0f6ecb9dd3b037
|
|
| MD5 |
6bf53f6dd4d55b516b8782c637f5f875
|
|
| BLAKE2b-256 |
30d03e3d5118abd129d06af01698d8165c4fa9ebaca889b048a356c2b09a1161
|