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):
Showcases
- murainbot-plugin-codeshare: Uses PowerText for multi-color code rendering.
License
Copyright 2025-2026 Xiaosu.
Distributed under the terms of the MPL 2.0 License.
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 powertext-0.7.1.tar.gz.
File metadata
- Download URL: powertext-0.7.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5afc271721856239e5dfe1fd03d2d0103e04474a8430883ac5c410bc558ce21e
|
|
| MD5 |
bb23d80ef75272a45eb74c5d6fd4f091
|
|
| BLAKE2b-256 |
b3eca13c7678101a5fa86d40c4f19b721b0024660a423dd4c22f48910a35e04a
|
Provenance
The following attestation bundles were made for powertext-0.7.1.tar.gz:
Publisher:
python-publish.yml on xiaosuyyds/PowerText
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
powertext-0.7.1.tar.gz -
Subject digest:
5afc271721856239e5dfe1fd03d2d0103e04474a8430883ac5c410bc558ce21e - Sigstore transparency entry: 1192127381
- Sigstore integration time:
-
Permalink:
xiaosuyyds/PowerText@75aeb43e47ddcb7a5509e4047d3b066716977a11 -
Branch / Tag:
refs/tags/0.7.1 - Owner: https://github.com/xiaosuyyds
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@75aeb43e47ddcb7a5509e4047d3b066716977a11 -
Trigger Event:
release
-
Statement type:
File details
Details for the file powertext-0.7.1-py3-none-any.whl.
File metadata
- Download URL: powertext-0.7.1-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
854d01e34f20ef5702370a54ad957ba7d9c23ad8d9fa207a237e7779a718a761
|
|
| MD5 |
937cf08f61c3c305431cabc7b50ceb10
|
|
| BLAKE2b-256 |
6cac64c3e3e13a3a6e388b7fabc37ac6d47646a26c976596a454b578b5d2a443
|
Provenance
The following attestation bundles were made for powertext-0.7.1-py3-none-any.whl:
Publisher:
python-publish.yml on xiaosuyyds/PowerText
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
powertext-0.7.1-py3-none-any.whl -
Subject digest:
854d01e34f20ef5702370a54ad957ba7d9c23ad8d9fa207a237e7779a718a761 - Sigstore transparency entry: 1192127384
- Sigstore integration time:
-
Permalink:
xiaosuyyds/PowerText@75aeb43e47ddcb7a5509e4047d3b066716977a11 -
Branch / Tag:
refs/tags/0.7.1 - Owner: https://github.com/xiaosuyyds
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@75aeb43e47ddcb7a5509e4047d3b066716977a11 -
Trigger Event:
release
-
Statement type: