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"),
        power_text.Font(font3, lambda char: jap.match(char) is not None),
        power_text.Font(font2, lambda _: True)
    ],
    (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.1.0.tar.gz (12.9 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.1.0-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for powertext-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bbd55000b2355112951ef0c95b7d3fe00118e7b434a2a0b469c51beb99273d20
MD5 031bd8f63f8cef39828d710cef52d3be
BLAKE2b-256 74e436f64bd2ce40f9dbd89a2363fa93888ad0f5d27cf48369db5164bd40372f

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: powertext-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.0 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af76f560527aa758ab10f405a4b61a696ef29bba80dc92effce328fe5ecf1d5e
MD5 b383cb7f54dc359c96c47fbb13068e20
BLAKE2b-256 1c43683ba0d9a347ca63aec96835749de02cd7c0c2a3c107d5d9ca5a005dbe60

See more details on using hashes here.

Provenance

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