Skip to main content

A text renderer for Pillow that supports emojis, multiple fonts, automatic line wrapping, and automatic text truncation.

Project description

PowerText

| English | 简体中文 |

📖 Introduction

PowerText is a text renderer for Pillow that supports emojis, multi-font matching, automatic word wrapping, and text truncation (auto-ellipsis).

⬇️ Installation

python -m pip install PowerText

Alternatively, you can install from source:

git clone https://github.com/xiaosuyyds/PowerText.git
python -m pip install .

🧑‍💻 Usage

Example Code

import power_text
import re
from PIL import Image, ImageFont
import emoji

# Regex for Japanese Kana
jap = re.compile(r'[\u3040-\u309F\u30A0-\u30FF]')

img = Image.new("RGB", (1150, 630), (255, 255, 255))
# Note: Please ensure you have these font files or replace them with your local font paths
font1 = ImageFont.truetype(r'PINGFANG MEDIUM.TTF', 24)
font2 = ImageFont.truetype(r'unifont-16.0.02.otf', 24)
font3 = ImageFont.truetype(r'Segoe UI.ttf', 24)
# Note: For fonts like Noto Color Emoji, pay attention to the font size (e.g., 109), 
# otherwise they may fail to load correctly.
font_emoji = ImageFont.truetype("NotoColorEmoji.ttf", 109)


power_text.draw_text(
    img,
    (10, 10),  # Starting xy coordinates

    """
皆さん✨、我在インターネット上看到someone把几国language混在一起speak🌍。我看到之后be like:それは我じゃないか!😂 私もtry一tryです🎉。虽然是混乱している句子ですけど、中文日本語プラスEnglish、挑戦スタート🚀!  

我study📖日本語的时候,もし有汉字,我会很happy😊。Bueause中国人として、when I see汉字,すぐに那个汉字がわかります✨。But 我hate😤外来語、什么マクドナルド🍔、スターバックス☕、グーグル🔍、ディズニーランド🏰、根本记不住カタカナhow to写、太難しい😭。  

以上です✌️,byebye👋!

awa
    """.strip(),
    [
        # Match Latin characters and numbers using font3 (Segoe UI), default color
        power_text.Font(font3, lambda data: data['text'].lower() in "abcdefghijklmnopqrstuvwxyz0123456789"),
        # Match Japanese Kana using font2 (unifont), colored blue
        power_text.Font(font2, lambda data: jap.match(data['text']) is not None, (22, 125, 255)),
        # Match emojis using font_emoji (Noto Color Emoji), set 'size' for automatic scaling to match text
        power_text.Font(font_emoji, lambda data: emoji.is_emoji(data['text']), size=24),
        # Fallback for other characters (e.g., CJK ideographs) using font1 (PingFang), colored red
        power_text.Font(font1, lambda _: True, (220, 20, 60))
    ],
    (0, 0, 0),  # Default font color (black)
    max_x=886,  # Maximum width (auto line wrap if exceeded)
    max_y=200,  # Maximum height (auto truncation if exceeded)
    end_text="..."  # Truncation symbol
)
img.show()

The output of the above code is as follows (Source Code):

image

Showcases

License

Copyright 2025-2026 Xiaosu.

Distributed under the terms of the MPL 2.0 License.

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

powertext-0.7.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

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

powertext-0.7.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file powertext-0.7.0.tar.gz.

File metadata

  • Download URL: powertext-0.7.0.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for powertext-0.7.0.tar.gz
Algorithm Hash digest
SHA256 7bc2e71301646d0e7fdf71bfcb20a2083f5c033f593cd9a4663e8cbbf44adba9
MD5 1aeed57d69cd8cbdbbd05bea875149f9
BLAKE2b-256 4007440eebfdacaf747debc61108790959c00e86907fc2e3ec9f276a5be9aaf9

See more details on using hashes here.

Provenance

The following attestation bundles were made for powertext-0.7.0.tar.gz:

Publisher: python-publish.yml on xiaosuyyds/PowerText

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file powertext-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: powertext-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for powertext-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06679ae35c45c69391909383acb1fcd537f52529a8feabe88bd06d5bb8ff2b14
MD5 353364f683d95f72318e6cd74cfc8e50
BLAKE2b-256 4db00846dd91ccbce15b697ff548e04e58ac4049aab864551f7f5d61b795e5c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for powertext-0.7.0-py3-none-any.whl:

Publisher: python-publish.yml on xiaosuyyds/PowerText

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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