Python bindings for imagetext
Project description
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:
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")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file imagetext_py-2.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: imagetext_py-2.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 7.0 MB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c370b06c1a84ed9f28bc939c401269097266802437cd344b10dd8fca152921f
|
|
| MD5 |
7abcbc6e21bdf18732cc6aede80b0172
|
|
| BLAKE2b-256 |
b5b4def635e818b1e78a28201f22c0addfe4fe57c712f08ce59dc5f3618e7236
|
File details
Details for the file imagetext_py-2.0.1-cp311-none-win_amd64.whl.
File metadata
- Download URL: imagetext_py-2.0.1-cp311-none-win_amd64.whl
- Upload date:
- Size: 3.7 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
286da2ed58ff2717798fda97aa15c1bf3bf390c1244675a39f407b30f82e431f
|
|
| MD5 |
2a9128a060587225b5f5ad9eb1ffd1b2
|
|
| BLAKE2b-256 |
303560e02111ccc29a8a1600257d94d570df7829911d3c56d9b01f669ff3f72e
|
File details
Details for the file imagetext_py-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: imagetext_py-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 7.0 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4d1437c32d60c5ab36db8c31c04b3b2fddd7c34086147adfac787c30cc9c7f8
|
|
| MD5 |
ebf67fcfab0638f451acc7beadbb3074
|
|
| BLAKE2b-256 |
d23d770906e5f914e2ffbee2239645402c9fac97fd459dfbdf5e3c12008cdf6a
|
File details
Details for the file imagetext_py-2.0.1-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.
File metadata
- Download URL: imagetext_py-2.0.1-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 8.4 MB
- Tags: CPython 3.11, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06774d4a1cd1865232e51456f784d259481e17522766fe22eb7fd77e16ca5717
|
|
| MD5 |
65ebdac6d75aec0a5d2f12cf9f2748f3
|
|
| BLAKE2b-256 |
04ec2a606b2e96b1a22f68a73ce80d4057328ca255e7bdbb86f4b7841535eda7
|
File details
Details for the file imagetext_py-2.0.1-cp310-none-win_amd64.whl.
File metadata
- Download URL: imagetext_py-2.0.1-cp310-none-win_amd64.whl
- Upload date:
- Size: 3.7 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1390275fb79caf016d2c9c687844fcb825ae152033c73897f5915a575676af6
|
|
| MD5 |
eb012a7fbab50ed802585389dec643fc
|
|
| BLAKE2b-256 |
560609904578566de84b90d15805995b3da2f76d11aa8cc4432965f301cdfe69
|
File details
Details for the file imagetext_py-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: imagetext_py-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 7.0 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44d812e0eaed64045b98973291f1afbef56f757351ecd328faac1b777ea03411
|
|
| MD5 |
f33d2855d9fc03fd04a4e0c5a827769b
|
|
| BLAKE2b-256 |
29fa6ed42851bc4f7dce77bdb4605192166a57253263ad4d77bc1a0b940dfd46
|
File details
Details for the file imagetext_py-2.0.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.
File metadata
- Download URL: imagetext_py-2.0.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 8.4 MB
- Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0324160d5ebac225fb33af17bcdbd81fa322f6d312c92d39a462cbfd85e289ca
|
|
| MD5 |
e02c7a23077abeab341cfa80a06099b6
|
|
| BLAKE2b-256 |
7dac8307ca9127f253d11e57267b7a25c044966e48d006296e480215db6ac6af
|
File details
Details for the file imagetext_py-2.0.1-cp39-none-win_amd64.whl.
File metadata
- Download URL: imagetext_py-2.0.1-cp39-none-win_amd64.whl
- Upload date:
- Size: 3.7 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
265b0df76ad86c3b924711f84b2bd1cdf8500d9fd19553830cbb69f701707194
|
|
| MD5 |
2d25a475a4fc9f9f0883bb882dca6b50
|
|
| BLAKE2b-256 |
0f2a83bfc0423019deb370f8b454e219f442d6f71f2b5879dcb8e7f229c197df
|
File details
Details for the file imagetext_py-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: imagetext_py-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 7.0 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a485150f3e929e87725c80a2706e1d94457770d33cbf6720e275bfb074d532c0
|
|
| MD5 |
94e8dd9fcb712310893b7e53e9c06abb
|
|
| BLAKE2b-256 |
df61542b67c7949d6a7d42146c3d7c7e0a41c8cb51352384fcc2576189e42395
|
File details
Details for the file imagetext_py-2.0.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.
File metadata
- Download URL: imagetext_py-2.0.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 8.4 MB
- Tags: CPython 3.9, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c8321787bb9f137552d7f707c2a16c3e195f99de0f04e1bc74529b82b66e0b4
|
|
| MD5 |
61f18e597685042d9615713da7740510
|
|
| BLAKE2b-256 |
a9f7b6d9002e44bb0891ee8b45d7f64bd1bfde08ce8e79f25b02433821b507a0
|