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.2.0.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.0-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: powertext-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 cdf603ad2a9fc57021c5a0a42a3b2bb7870989499ace6f2d972eb0944117f554
MD5 fdd7be787fffebed3342be9c6253b4f1
BLAKE2b-256 4baa04fdfab3fef9b664f390bef9de90f1b60b656d535ae0e3197c9633afbf1e

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: powertext-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 17.1 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22b1975e67d16e7a8d733882809ec1f96e29cfc7e749c60ee7fe110cceaab60c
MD5 0eb71d40e35bb80ea51da638d11672d4
BLAKE2b-256 21eb2f9157eb4ff941a073afb82856245db16020658d4303ff1d9e4708071f5f

See more details on using hashes here.

Provenance

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