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.3.1.tar.gz (13.7 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.3.1-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for powertext-0.3.1.tar.gz
Algorithm Hash digest
SHA256 eec22f5316cc385bd07f9b1fca5282d2e0f4771c471f07e174ed55b9bb51c94b
MD5 77af509c8dd89c3f27abeed8ee4401c0
BLAKE2b-256 b1032017e85c42ca4b8433b568ea476839b06f9a00fd7dabe908ec67f632c6a7

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: powertext-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 17.9 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 603be19cc81031e8d588277ba55d59dcc60e78ddc765b78137c3da83ac48608d
MD5 49bfdfaba121a5036999043072c580e6
BLAKE2b-256 2c7f747cadb5a57e1f20fe661d3fc0f8c87876f5a1b1169873b70d3e9c0b11af

See more details on using hashes here.

Provenance

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