Skip to main content

hero banner

A blazing fast text drawing library

imagetext-py is python bindings for imagetext

CI

About

imagetext makes use of rusttype for font parsing and tiny-skia for drawing. It has a simple API that allows you to draw text with ease.

Features

  • Multi-line text
  • Text wrapping
  • Text alignment
  • Font fallbacks
  • Text stroke
  • Gradient fills
  • Emojis! (almost every platform supported)
  • Global Font Database with css-like font querying

Installation

pip install imagetext-py

Example Usage

from PIL import Image
from imagetext_py import *

# supports fonts with fallbacks
font = Font("coolvetica.ttf", fallbacks=["emojis.ttf", "japanese.otf"])

# create a canvas to draw on
cv = Canvas(512, 512, (255, 255, 255, 255))

# paints are used to fill and stroke text
black = Paint.Color((0, 0, 0, 255))
rainbow = Paint.Rainbow((0.0,0.0), (256.0,256.0))

# if a font doesn't have a glyph for a character, it will use the fallbacks
text = "hello my 😓 n🐢ame i☕s 会のすべ aての構成員 nathan and i drink soup boop coop, the quick brown fox jumps over the lazy dog"

draw_text_wrapped(canvas=cv,              # the canvas to draw on
                  text=text, 
                  x=256, y=256,           # the position of the text
                  ax=0.5, ay=0.5,         # the anchor of the text
                  size=67,                # the size of the text
                  width=500,              # the width of the text
                  font=font,              
                  fill=black,
                  align=TextAlign.Center,
                  stroke=2.0,             # the stroke width (optional)
                  stroke_color=rainbow)   # the stroke color (optional)

# you can convert the canvas to a PIL image
im: Image.Image = cv.to_image()
im.save("test.png")

# or you can just get the raw bytes
dimensions, bytes = cv.to_bytes()

# you can also save directly to a file
cv.save("test.png")

produces this image:

test.png

took 6ms to draw this on my machine

Pillow and FontDB Usage

from PIL import Image
from imagetext_py import *

FontDB.SetDefaultEmojiOptions(EmojiOptions(allow_discord=True))
FontDB.LoadFromDir(".")

font = FontDB.Query("coolvetica japanese")

with Image.new("RGBA", (512, 512), "white") as im:
    with Writer(im) as w:
        w.draw_text_wrapped(
            text="hello from python 😓 lol, <:blobpain:739614945045643447> " \
                 "ほまみ <:chad:682819256173461522><:bigbrain:744344773229543495> " \
                 "emojis workin",
            x=256, y=256,
            ax=0.5, ay=0.5,
            width=512,
            size=90,
            font=font,
            fill=Paint.Color((0, 0, 0, 255)),
            align=TextAlign.Center,
            stroke=2.0,
            stroke_color=Paint.Rainbow((0.0,0.0), (256.0,256.0)),
            draw_emojis=True
        )
    im.save("test.png")

Release files for imagetext-py 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for imagetext-py 2.0.1
File
imagetext_py-2.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl PyPy 3.9 PyPy 3.9 7.3 Linux glibc 2.17+ x86-64 Details
imagetext_py-2.0.1-cp311-none-win_amd64.whl CPython 3.11 none Windows x86-64 Details
imagetext_py-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
imagetext_py-2.0.1-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl CPython 3.11 CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64), macOS 11.0+ ARM64, macOS 10.9+ x86-64 Details
imagetext_py-2.0.1-cp310-none-win_amd64.whl CPython 3.10 none Windows x86-64 Details
imagetext_py-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
imagetext_py-2.0.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64, macOS 10.9+ x86-64, macOS 10.9+ universal2 (ARM64, x86-64) Details
imagetext_py-2.0.1-cp39-none-win_amd64.whl CPython 3.9 none Windows x86-64 Details
imagetext_py-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
imagetext_py-2.0.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl CPython 3.9 CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64), macOS 11.0+ ARM64, macOS 10.9+ x86-64 Details

Total release size:64.4 MB

Release files / imagetext_py-2.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL imagetext_py-2.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 7.0 MB
Tags Linux glibc 2.17+ x86-64 PyPy 3.9 PyPy 3.9 7.3
SHA-256 checksum
How to use checksums
1c370b06c1a84ed9f28bc939c401269097266802437cd344b10dd8fca152921f
BLAKE2b-256 checksum
How to use checksums
b5b4def635e818b1e78a28201f22c0addfe4fe57c712f08ce59dc5f3618e7236
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.14.10

Release files / imagetext_py-2.0.1-cp311-none-win_amd64.whl

Download URL imagetext_py-2.0.1-cp311-none-win_amd64.whl
Size 3.7 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
286da2ed58ff2717798fda97aa15c1bf3bf390c1244675a39f407b30f82e431f
BLAKE2b-256 checksum
How to use checksums
303560e02111ccc29a8a1600257d94d570df7829911d3c56d9b01f669ff3f72e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.14.10

Release files / imagetext_py-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL imagetext_py-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 7.0 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
b4d1437c32d60c5ab36db8c31c04b3b2fddd7c34086147adfac787c30cc9c7f8
BLAKE2b-256 checksum
How to use checksums
d23d770906e5f914e2ffbee2239645402c9fac97fd459dfbdf5e3c12008cdf6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.14.10

Release files / imagetext_py-2.0.1-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl

Download URL imagetext_py-2.0.1-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Size 8.4 MB
Tags CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
06774d4a1cd1865232e51456f784d259481e17522766fe22eb7fd77e16ca5717
BLAKE2b-256 checksum
How to use checksums
04ec2a606b2e96b1a22f68a73ce80d4057328ca255e7bdbb86f4b7841535eda7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.14.10

Release files / imagetext_py-2.0.1-cp310-none-win_amd64.whl

Download URL imagetext_py-2.0.1-cp310-none-win_amd64.whl
Size 3.7 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
f1390275fb79caf016d2c9c687844fcb825ae152033c73897f5915a575676af6
BLAKE2b-256 checksum
How to use checksums
560609904578566de84b90d15805995b3da2f76d11aa8cc4432965f301cdfe69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.14.10

Release files / imagetext_py-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL imagetext_py-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 7.0 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
44d812e0eaed64045b98973291f1afbef56f757351ecd328faac1b777ea03411
BLAKE2b-256 checksum
How to use checksums
29fa6ed42851bc4f7dce77bdb4605192166a57253263ad4d77bc1a0b940dfd46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.14.10

Release files / imagetext_py-2.0.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl

Download URL imagetext_py-2.0.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Size 8.4 MB
Tags CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0324160d5ebac225fb33af17bcdbd81fa322f6d312c92d39a462cbfd85e289ca
BLAKE2b-256 checksum
How to use checksums
7dac8307ca9127f253d11e57267b7a25c044966e48d006296e480215db6ac6af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.14.10

Release files / imagetext_py-2.0.1-cp39-none-win_amd64.whl

Download URL imagetext_py-2.0.1-cp39-none-win_amd64.whl
Size 3.7 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
265b0df76ad86c3b924711f84b2bd1cdf8500d9fd19553830cbb69f701707194
BLAKE2b-256 checksum
How to use checksums
0f2a83bfc0423019deb370f8b454e219f442d6f71f2b5879dcb8e7f229c197df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.14.10

Release files / imagetext_py-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL imagetext_py-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 7.0 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a485150f3e929e87725c80a2706e1d94457770d33cbf6720e275bfb074d532c0
BLAKE2b-256 checksum
How to use checksums
df61542b67c7949d6a7d42146c3d7c7e0a41c8cb51352384fcc2576189e42395
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.14.10

Release files / imagetext_py-2.0.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl

Download URL imagetext_py-2.0.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Size 8.4 MB
Tags CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0c8321787bb9f137552d7f707c2a16c3e195f99de0f04e1bc74529b82b66e0b4
BLAKE2b-256 checksum
How to use checksums
a9f7b6d9002e44bb0891ee8b45d7f64bd1bfde08ce8e79f25b02433821b507a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.14.10

Release history Release notifications | RSS feed

2.2.1

16 release files

2.2.0

16 release files

2.1.3

10 release files

2.1.2

10 release files

2.1.1

10 release files

2.1.0

10 release files

2.0.2

10 release files

This release

2.0.1 This release

10 release files

1.0.2

19 release files

1.0.1

19 release files

1.0.0

19 release files

0.1.0

19 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page