Skip to main content

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))
font1 = ImageFont.truetype(r'SmileySans-Oblique.ttf', 24)
font2 = ImageFont.truetype(r'PINGFANG MEDIUM.TTF', 24)
font3 = ImageFont.truetype(r'unifont-16.0.02.otf', 24)
font4 = 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(),
    [
        power_text.Font(font4, lambda char: char.lower() in "abcdefghijklmnopqrstuvwxyz0123456789", (0, 0, 0)),
        power_text.Font(font3, lambda char: jap.match(char) is not None, (22, 125, 255)),
        power_text.Font(font2, lambda _: True, (220, 20, 60))
    ],
    (0, 0, 0),  # Font color
    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, which may be slow 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"noto-emoji-main\png\128")
)

To set the emoji_source, provide the path to the local folder containing emoji images. You can obtain emoji images from this project and download any resolution folder to your local machine.

The output of the above code looks like this:

image

License

Copyright 2025 Xiaosu.

Distributed under the terms of the Apache 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.2.3.tar.gz (13.0 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.2.3-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for powertext-0.2.3.tar.gz
Algorithm Hash digest
SHA256 4befffcec0d46a1741294128cb2a5ea90d8495558ac5d74f227f62bb52799ba9
MD5 ce21d2a97687e13f343aa15771af333a
BLAKE2b-256 6b27ce7aa47a956340dd65fd89b37c0b4245d6e9f7f384c1417820e8847d47ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for powertext-0.2.3.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.2.3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for powertext-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 26a0f027de257d64e9027d75b71cbef04d0fff1b063182e3659f9680c7577090
MD5 dffa2201f1b51b31de90ca0b963f52fc
BLAKE2b-256 98f225ceb125edae4a032b94f62961c35756175efa404824bee833491c01e5e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for powertext-0.2.3-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