Skip to main content

Pilmoji for nonebot-plugin-parser

Project description

Apilmoji

A high-performance asynchronous emoji rendering library

LICENSE pypi python ruff pre-commit codecov

✨ Features

  • 🎨 Unicode Emoji Support - Render standard Unicode emojis
  • 💬 Discord Emoji Support - Render custom Discord emojis
  • 🔄 Concurrent Downloads - Support concurrent emoji downloads for better performance
  • 💾 Smart Caching - Local file caching to avoid repeated downloads
  • 🎭 Multiple Styles - Support for Apple, Google, Twitter, Facebook, and other styles
  • 📊 Progress Display - Optional progress bar for download progress

📦 Installation

Requirements: Python 3.10 or higher

uv add apilmoji

Or install from source:

uv add git+https://github.com/fllesser/apilmoji

🚀 Quick Start

Basic Usage (Unicode Emojis Only)

import asyncio
from PIL import Image, ImageFont
from apilmoji import Apilmoji

async def main():
    text = '''
    Hello, world! 👋
    Here are some emojis: 🎨 🌊 😎
    Supports multi-line text! 🚀 ✨
    '''

    # Create image
    image = Image.new('RGB', (550, 150), (255, 255, 255))
    font = ImageFont.truetype('arial.ttf', 24)

    # Render text with emojis
    await Apilmoji.text(
        image,
        (10, 10),
        text.strip(),
        font,
        fill=(0, 0, 0)
    )

    image.save('output.png')
    image.show()

asyncio.run(main())

Discord Emoji Support

async def main():
    text = '''
    Unicode emojis: 👋 🎨 😎
    Discord emojis: <:rooThink:123456789012345678>
    '''

    image = Image.new('RGB', (550, 100), (255, 255, 255))
    font = ImageFont.truetype('arial.ttf', 24)

    await Apilmoji.text(
        image,
        (10, 10),
        text.strip(),
        font,
        fill=(0, 0, 0),
        support_ds_emj=True  # Enable Discord emoji support
    )

    image.save('output.png')

asyncio.run(main())

🎨 Emoji Styles

Choose different emoji styles:

from apilmoji import Apilmoji, EmojiCDNSource, EmojiStyle

# 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)

await Apilmoji.text(
    image,
    (10, 10),
    "Hello 👋",
    font,
    source=source
)

🔧 API Reference

Apilmoji.text

Main text rendering method.

await Apilmoji.text(
    image: PILImage,
    xy: tuple[int, int],
    lines: list[str] | str,
    font: FontT,
    *,
    fill: ColorT | None = None,
    line_height: int | None = None,
    support_ds_emj: bool = False,
    source: EmojiCDNSource | None = None,
) -> None

Parameters:

  • image: PIL Image object for rendering
  • xy: (x, y) coordinate tuple for text position
  • lines: Text lines to render (supports multi-line)
  • font: PIL Font object
  • fill: Text color (default: black)
  • line_height: Line height (default: font height)
  • support_ds_emj: Whether to support Discord emojis (default: False)
  • source: Emoji source (default: EmojiCDNSource())

EmojiCDNSource

Default emoji source using emojicdn.elk.sh.

EmojiCDNSource(
    base_url: str = "https://emojicdn.elk.sh",
    style: EmojiStyle = EmojiStyle.APPLE,
    *,
    cache_dir: Path | None = None,
    enable_discord: bool = False,
    max_concurrent: int = 50,
    enable_tqdm: bool = False,
)

Parameters:

  • base_url: CDN base URL
  • style: Emoji style
  • cache_dir: Custom cache directory (default: ~/.cache/apilmoji)
  • enable_discord: Enable Discord emoji support
  • max_concurrent: Maximum concurrent downloads (default: 50)
  • enable_tqdm: Enable progress bar display

📝 Advanced Usage

Custom Line Height and Color

# Custom line height and color
await Apilmoji.text(
    image,
    (10, 10),
    "Custom styling 🎨",
    font,
    fill=(255, 0, 0),      # Red text
    line_height=40,        # Custom line height
    support_ds_emj=True
)

Enable Progress Bar

from apilmoji import EmojiCDNSource

# Enable progress bar display
source = EmojiCDNSource(enable_tqdm=True)

await Apilmoji.text(
    image,
    (10, 10),
    "Emoji download with progress bar 📊",
    font,
    source=source
)

Adjust Concurrency

# Adjust concurrent download count
source = EmojiCDNSource(max_concurrent=10)  # Limit to 10 concurrent

await Apilmoji.text(
    image,
    (10, 10),
    "Limited concurrent downloads ⚡",
    font,
    source=source
)

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🐛 Issues

If you encounter any issues, please report them on the GitHub Issues page.

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

apilmoji-0.2.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

apilmoji-0.2.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file apilmoji-0.2.0.tar.gz.

File metadata

  • Download URL: apilmoji-0.2.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

Hashes for apilmoji-0.2.0.tar.gz
Algorithm Hash digest
SHA256 abee9d9dd12e5e5aa8ec6f597c32598c139fb380bb8384b5e8cf1ebf8c9c55df
MD5 448f6bf430c4b39d25f9a12a6d4da7b2
BLAKE2b-256 31c468b827b92b79ffeec35ca3d32c57e26e40050bc4f2a4c983fbdc72ac8449

See more details on using hashes here.

File details

Details for the file apilmoji-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: apilmoji-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 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

Hashes for apilmoji-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a0103f8f8d5492628902f9857a6bfc11906361ad38df72efec3f08b944306c7
MD5 bb5e188d3b7e5b85e4bbace858daeccd
BLAKE2b-256 8c2579675137b41f28af1e7142ccbc197d40fdd6c8353269f0843806c7fd0cb1

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