if you found this library useful, consider leaving a star ⭐
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.
Currently imagetext-py does beat out Pillow for most of the cases I've tested, but I will setup some benchmarks soon.
Features
- Multi-line text
- Text wrapping
- Text alignment
- Font fallbacks
- Text stroke
- Gradient fills
- Emojis! (almost every platform supported, including discord)
- Global Font Database with css-like font querying
Note: emojis are fetched and cached from the internet during runtime, so you will need an internet connection to use them. The ability to use local emoji images will be added soon.
Installation
pip install imagetext-py
Example Usage
from PIL import Image
from imagetext_py import *
# supports fonts with fallbacks
FontDB.LoadFromDir(".")
font = FontDB.Query("coolvetica japanese")
# 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,
draw_emojis=True) # 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:
Pillow and FontDB Usage
from PIL import Image
from imagetext_py import *
FontDB.SetDefaultEmojiOptions(EmojiOptions(parse_discord_emojis=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=500,
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")
produces this image:
Release files for imagetext-py 2.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size:96.8 MB
Release files / imagetext_py-2.2.1-cp38-abi3-win_arm64.whl
| Download URL | imagetext_py-2.2.1-cp38-abi3-win_arm64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.8 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
1fa5b6023146391bb0b840e097f53d62e1ba7bb4f11ae2a83e74168eb1c69543
|
|
BLAKE2b-256 checksum How to use checksums |
a39c40c0b8898d19ef2ace536350b5d61adab714e33b7584c22e53711d7741c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / imagetext_py-2.2.1-cp38-abi3-win_amd64.whl
| Download URL | imagetext_py-2.2.1-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 3.9 MB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
4a246cb6522d6a9723faff6911ac589ff54d7371a7dc831195d9b672063ddc7a
|
|
BLAKE2b-256 checksum How to use checksums |
09bc86539bf10812052a3543179a6d60c2ff5f47766674c9272a09a49a87d164
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / imagetext_py-2.2.1-cp38-abi3-win32.whl
| Download URL | imagetext_py-2.2.1-cp38-abi3-win32.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.8 Windows x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
92f3affe30725394c9bd0be29bedcd6f8583fcc5a2f6c1b4069019bc82ea08aa
|
|
BLAKE2b-256 checksum How to use checksums |
e7920913dc58f0310b5eed33efb60255356959ab5d309335ddb4ef7cc60c88e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_x86_64.whl
| Download URL | imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 6.8 MB |
| Tags | CPython 3.8 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
0cb4dfba512a2049d336675b69454c578175e7c3e78ca0bf13406c75baa16087
|
|
BLAKE2b-256 checksum How to use checksums |
edbef79931b3feaae62e0d58b685026656bd8cf3891f1e9263ae5d7aec07e6ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_i686.whl
| Download URL | imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_i686.whl |
|---|---|
| Size | 6.7 MB |
| Tags | CPython 3.8 Linux musl 1.2+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
ec3c24aa117eece6a31e6876d8dd44578acb07ad135537ecf77aeb42da7364c1
|
|
BLAKE2b-256 checksum How to use checksums |
f3b18442d4e58e312409f3b8a95438b6adf2168574a80b21cde06f826476ec31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_armv7l.whl
| Download URL | imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_armv7l.whl |
|---|---|
| Size | 6.4 MB |
| Tags | CPython 3.8 Linux musl 1.2+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
61cf6b8f746a22bf7b06a013e56c3f364a21bf5b10bc28f7b72d4df9c38d443c
|
|
BLAKE2b-256 checksum How to use checksums |
5b2378fa31a1f5c423f09ea8b351576ab1a72a3df54c2f592fe13cddff7b0787
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_aarch64.whl
| Download URL | imagetext_py-2.2.1-cp38-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 7.1 MB |
| Tags | CPython 3.8 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
e6af78fe8af536698599c784f55efea68d685441c0d718e4606a0c6f451d8646
|
|
BLAKE2b-256 checksum How to use checksums |
de7511635275dba7e00daa62df084b3af63f5a6d7a183ca061affd49da3e6643
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 6.4 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
60aaacd5aa24383e6c0ae8d132de5db882eef733b38d05a70fc90bfa70d198ea
|
|
BLAKE2b-256 checksum How to use checksums |
d6f031e3e12eae7469c8f23de3fce0ca1fb890c3ecafe1d97f0b9cb2be58d0e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
| Download URL | imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl |
|---|---|
| Size | 6.5 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ IBM System/390x abi3 |
|
SHA-256 checksum How to use checksums |
c2d5b8b941740a51839ac7a5933e6a50b58b8717cc275b9964b8bd1e0d80491d
|
|
BLAKE2b-256 checksum How to use checksums |
367712711b5224c01bd48f1ce62634a2eadba2139317dc5a5036307dea163bed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 6.8 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
cb955668bfb510f7fbaf321022fb85bbbb4397252d572145fa1553e23f85e2f4
|
|
BLAKE2b-256 checksum How to use checksums |
ca35b9776e5f4792f2f926dcd8c14fc5594542e84a9822a156788c9e9aa0c72e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
| Download URL | imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_ppc64.manylinux2014_ppc64.whl |
|---|---|
| Size | 7.0 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ PowerPC 64-be abi3 |
|
SHA-256 checksum How to use checksums |
11e3cbd880a7278a84e0b38f8c043d3684dec2f25b5e37b4dc3d837229137fda
|
|
BLAKE2b-256 checksum How to use checksums |
67f228a05ce142ac86d549cc5c54dbe0b9154b4ef1db57a45906667afb9de1c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 6.7 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
8f71ca6ccfa23ff8858fb2777c5ac5fdf22ecef2e71b8cc23e1a8e444df17065
|
|
BLAKE2b-256 checksum How to use checksums |
1543461016dac0e81a52b0e50d321be5d1a16b827b127b52f583f85db00f3ce7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
| Download URL | imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl |
|---|---|
| Size | 6.1 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
71908e62705fa1fb5cd1c4f74fc5e0b4b6e1d24d87ea9be9c45bd3196c3be05f
|
|
BLAKE2b-256 checksum How to use checksums |
d30c1e9840be92b2f1aa4fe65f65b64475f377fd0a04e838040fa5e4d789dc9f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | imagetext_py-2.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 6.7 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
cb376bef61643c2e7ae56dff1c8dbc21a676cdf065a76946541661837b325413
|
|
BLAKE2b-256 checksum How to use checksums |
cdfd1f0e9b1d90a47cf25f8cf340dca99d3f4ff1d67e0e9d9a5ccbbe43530cb4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / imagetext_py-2.2.1-cp38-abi3-macosx_10_12_x86_64.whl
| Download URL | imagetext_py-2.2.1-cp38-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 4.2 MB |
| Tags | CPython 3.8 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
27079cbe39410f06637e6ef24c735888b26332c97a22c97e13ae7854be312a2d
|
|
BLAKE2b-256 checksum How to use checksums |
7ea635cb4e1e17897c94e51dae170f32bae424931dfcd28b93ba5718318a911b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / imagetext_py-2.2.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
| Download URL | imagetext_py-2.2.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl |
|---|---|
| Size | 8.2 MB |
| Tags | CPython 3.8 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a1702c9584c1ea69790ec0cbc918a8cb73047926d8228303948ee065c6785629
|
|
BLAKE2b-256 checksum How to use checksums |
16da6dbf5d493b9f7363755414de54d92cb016a81c017c9bc17f0eb9a3b993d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|