PowerText is 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, multiple fonts, automatic line wrapping, and automatic truncation.
⬇️ Installation
python -m pip install PowerText
Of course, you can also install it from the source:
git clone https://github.com/xiaosuyyds/PowerText.git
python -m pip install .
Note! By default, only the necessary dependencies are installed. If you need emoji rendering, please install:
python -m pip install PowerText[full]
or
git clone https://github.com/xiaosuyyds/PowerText.git
python -m pip install .[full]
🧑💻 Usage
Example Code
import power_text
import re
from PIL import Image, ImageFont
jap = re.compile(r'[\u3040-\u309F\u30A0-\u30FF]')
img = Image.new("RGB", (1150, 630), (255, 255, 255))
# Note: Ensure you have these font files or replace with paths to fonts you have
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)
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, use font3 (Segoe UI), color default
power_text.Font(font3, lambda char: char.lower() in "abcdefghijklmnopqrstuvwxyz0123456789"),
# Match Japanese Hiragana/Katakana, use font2 (unifont), color blue
power_text.Font(font2, lambda char: jap.match(char) is not None, (22, 125, 255)),
# Fallback for other characters (like CJK), use font1 (PingFang), color 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)
has_emoji=True, # Enable emoji support
end_text="..." # Truncation symbol
)
img.show()
Tips:
By default, the emoji source is online (Twemoji), which may be slow to access in some regions. You can use a local source instead:
import power_text
from power_text import local_emoji_source
power_text.draw_text(
...,
emoji_source=local_emoji_source.LocalEmojiSource(r"path/to/your/noto-emoji-main/png/128") # Replace with your actual path
)
To set the emoji_source, provide the path to the local folder containing emoji images (e.g., PNGs). You can obtain emoji images from Google's Noto Emoji project. Download the png folder for a specific resolution (like 128) to your local machine and point LocalEmojiSource to that directory.
The output of the above code looks like this(Draw code):
Use Cases
- murainbot-plugin-codeshare Uses PowerText for multi-color code rendering.
License
Copyright 2025 Xiaosu.
Distributed under the terms of the Apache 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.5.0.tar.gz.
File metadata
- Download URL: powertext-0.5.0.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
592fac6e243b4e92b08b154afd78249a535d94623d0ed7511b1427db2748981c
|
|
| MD5 |
146dd020f34d892a9f9c802c773163b1
|
|
| BLAKE2b-256 |
a8532f0d4486104d1527f6569eeeb03f32102308771080c2922537ce23a348f3
|
Provenance
The following attestation bundles were made for powertext-0.5.0.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.5.0.tar.gz -
Subject digest:
592fac6e243b4e92b08b154afd78249a535d94623d0ed7511b1427db2748981c - Sigstore transparency entry: 206453796
- Sigstore integration time:
-
Permalink:
xiaosuyyds/PowerText@eb1bab54d17b47e3606217cd369460804e7fe6f5 -
Branch / Tag:
refs/tags/0.5.0 - Owner: https://github.com/xiaosuyyds
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@eb1bab54d17b47e3606217cd369460804e7fe6f5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file powertext-0.5.0-py3-none-any.whl.
File metadata
- Download URL: powertext-0.5.0-py3-none-any.whl
- Upload date:
- Size: 19.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
788c871f8f73497955a63e59bd280b08988f6afbd10718af8449bec1fb124a09
|
|
| MD5 |
3971fe18495835c574da723d6dec2ac6
|
|
| BLAKE2b-256 |
531fec6f0bc9b87113bf35a10c10f210baedb7f96cf19953963746965d24e395
|
Provenance
The following attestation bundles were made for powertext-0.5.0-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.5.0-py3-none-any.whl -
Subject digest:
788c871f8f73497955a63e59bd280b08988f6afbd10718af8449bec1fb124a09 - Sigstore transparency entry: 206453798
- Sigstore integration time:
-
Permalink:
xiaosuyyds/PowerText@eb1bab54d17b47e3606217cd369460804e7fe6f5 -
Branch / Tag:
refs/tags/0.5.0 - Owner: https://github.com/xiaosuyyds
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@eb1bab54d17b47e3606217cd369460804e7fe6f5 -
Trigger Event:
release
-
Statement type: