Python bindings for imagetext
Project description
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:
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
File details
Details for the file imagetext_py-2.2.0-cp38-abi3-win_arm64.whl
.
File metadata
- Download URL: imagetext_py-2.2.0-cp38-abi3-win_arm64.whl
- Upload date:
- Size: 3.6 MB
- Tags: CPython 3.8+, Windows ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be05b30b9301e699b3470ff109f8af28d8ce3e1d9e9738cdbf68e7889b86b7a5 |
|
MD5 | e2f8426c3374ce0b451b70f86bef9377 |
|
BLAKE2b-256 | 00b3f695fdcd0f1a2b37a96d37871894fd771f24249db0e03273ee36bbf55897 |
File details
Details for the file imagetext_py-2.2.0-cp38-abi3-win_amd64.whl
.
File metadata
- Download URL: imagetext_py-2.2.0-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 3.7 MB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3fbf7e985cc8ac234a210e4b6f439560d902d705610b9af1f5ceb0a61f70933 |
|
MD5 | f227610889f8e50ee9504a99c0b52d82 |
|
BLAKE2b-256 | 3a473cbb0ad13ad933db516ea98d78180b222f74a72ab0432d588bac3f480a35 |
File details
Details for the file imagetext_py-2.2.0-cp38-abi3-win32.whl
.
File metadata
- Download URL: imagetext_py-2.2.0-cp38-abi3-win32.whl
- Upload date:
- Size: 3.6 MB
- Tags: CPython 3.8+, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47ced40dffe6cd2a802b40351a5586679d13ad18b88ebf15143f86131f6c4bf4 |
|
MD5 | 4391b6516e5bf2be09068175d12a7d6b |
|
BLAKE2b-256 | 5a98c33ec0c25fd09efa34f4a9a86a09dfab1fb1cb3acb28b37042b44960de34 |
File details
Details for the file imagetext_py-2.2.0-cp38-abi3-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: imagetext_py-2.2.0-cp38-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 7.5 MB
- Tags: CPython 3.8+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae3217cef584faefd30eb9ad41d39e89809ec7c427dc2f916abc80170355213a |
|
MD5 | ec67fc863033b414edf73b01941ce34d |
|
BLAKE2b-256 | 79db0de55192371dd23c570e1f7adb8094eb84b34842865fd30cdbb084784c34 |
File details
Details for the file imagetext_py-2.2.0-cp38-abi3-musllinux_1_2_i686.whl
.
File metadata
- Download URL: imagetext_py-2.2.0-cp38-abi3-musllinux_1_2_i686.whl
- Upload date:
- Size: 7.4 MB
- Tags: CPython 3.8+, musllinux: musl 1.2+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c342dd2214445c95e89ad9c346956360831fb4075fd38d33e51481674240596 |
|
MD5 | 9fe360583607d19d6027d2bd2aa07b7d |
|
BLAKE2b-256 | c528beba52a79538570c7d6bb75b42164236caff02a2e87dab3f9e0611632490 |
File details
Details for the file imagetext_py-2.2.0-cp38-abi3-musllinux_1_2_armv7l.whl
.
File metadata
- Download URL: imagetext_py-2.2.0-cp38-abi3-musllinux_1_2_armv7l.whl
- Upload date:
- Size: 7.2 MB
- Tags: CPython 3.8+, musllinux: musl 1.2+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3db2bad720bd0d1656945c94f22d286b479d02d93f9095409ab627b57b8a55b |
|
MD5 | 72db7184f3849e6c786208e1f1803564 |
|
BLAKE2b-256 | fdbbbfa3b8ed9d693f31a521d6db4e0c641ef72b1dbf6b7adeb1931eb37e4578 |
File details
Details for the file imagetext_py-2.2.0-cp38-abi3-musllinux_1_2_aarch64.whl
.
File metadata
- Download URL: imagetext_py-2.2.0-cp38-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 7.9 MB
- Tags: CPython 3.8+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3b8b219afb8f567038ad44923f29b22af04bcd08185d2fea5d9880902b9c4fd |
|
MD5 | 7c260f1cdd3f067a2e04a8f57d09d541 |
|
BLAKE2b-256 | 16d6c5f569f9475e753c2254e4d7f355664319583a2be21883cd6481cb2466fa |
File details
Details for the file imagetext_py-2.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: imagetext_py-2.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 7.4 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eeebba3b2a2517c79bb800e6cb2a49921d9e89866e661736e5db26c5c0ede43c |
|
MD5 | dfdee0dcdbfa32b7ad3d899fc4f8bfe2 |
|
BLAKE2b-256 | daaf6642a22723a86b023268c01367500bfd3b253e3803f7910527c2716dd50b |
File details
Details for the file imagetext_py-2.2.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
.
File metadata
- Download URL: imagetext_py-2.2.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
- Upload date:
- Size: 7.7 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ s390x
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3506b59272ee458c91f847cc026759f8a31451e0416ebe8179c260861d88bcf |
|
MD5 | 77edba6768296a443813fd927e6ea09e |
|
BLAKE2b-256 | 00824da3ed12ab2a923a72c0ef554b21191fd2af4988b40bda89aad4c6d21117 |
File details
Details for the file imagetext_py-2.2.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
.
File metadata
- Download URL: imagetext_py-2.2.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
- Upload date:
- Size: 7.9 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ppc64le
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66d1b4263025f0b8805c0f2c0405047439f49570f7e87d16d950962ab39f6b89 |
|
MD5 | ac5f60bd464b63b2bc8b4f9718c48f90 |
|
BLAKE2b-256 | dcc86983cfe313fc2aad12b3a5fa2f588e712a665b00d6bc36ec416dda5a1e63 |
File details
Details for the file imagetext_py-2.2.0-cp38-abi3-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
.
File metadata
- Download URL: imagetext_py-2.2.0-cp38-abi3-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
- Upload date:
- Size: 8.2 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ppc64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | de05742ddeb093d21450fc406a22f581a976039a02a5ad2394e5f4ed51090ab2 |
|
MD5 | 89456d3de72ab53f173ee42e3a8486cf |
|
BLAKE2b-256 | 541ffbb7b7a5856f0ea63c2765758d24c7c3bc458108635bbf58c7e76928cd59 |
File details
Details for the file imagetext_py-2.2.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: imagetext_py-2.2.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 7.5 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b9420487ffe57272fe39254080ea2f0b2e98fe0d570f1754510092a956807fc |
|
MD5 | a5a6455006884382b7748bf2d56be90a |
|
BLAKE2b-256 | b4b80bf2be1bfcaef002082ebcf8c9b707bb70953e0e64c9c1e12a85603b20b9 |
File details
Details for the file imagetext_py-2.2.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
.
File metadata
- Download URL: imagetext_py-2.2.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
- Upload date:
- Size: 6.9 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0f9d9014a8f0c48c8fc7ba7df77b1f8ca75621725aa29f76aec4fd860963e52 |
|
MD5 | ab3b65d3ac4838df659627a4b2dfecdd |
|
BLAKE2b-256 | 12cae5632cb106b377c6e4f93812538e346ad3fe8511d3e405a2a57b1f73e1f8 |
File details
Details for the file imagetext_py-2.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: imagetext_py-2.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 7.6 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c8fd07676b189073b7e56811cac9095d95d355dd83b060bf4a3d0fe437953b1 |
|
MD5 | 98f1cb96619c177ae3de31c8b6d965f5 |
|
BLAKE2b-256 | 45a13afc4b512d83ff3eb97c38ad6336e9b824f3d364e812ae64316198db6abb |
File details
Details for the file imagetext_py-2.2.0-cp38-abi3-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: imagetext_py-2.2.0-cp38-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 4.1 MB
- Tags: CPython 3.8+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a91d3b06047b54ca8579647b7b8f65df089be1a1431963c752cd1dddf0ab0d9a |
|
MD5 | 8858b4008b862f6e52ff9713e8357c8e |
|
BLAKE2b-256 | d99da47a2c1b7a1e7934028136c69e6c397b2d057c792f859bbde5df082800de |
File details
Details for the file imagetext_py-2.2.0-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
.
File metadata
- Download URL: imagetext_py-2.2.0-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
- Upload date:
- Size: 8.1 MB
- Tags: CPython 3.8+, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10578502c27279c3b04d0145374d42904b1fa2ec1f1f2d8f2a8155cbe0759235 |
|
MD5 | b8ef2de810c6eff68ddece6c7415a42d |
|
BLAKE2b-256 | a3e7c1e95eaea0ad56c44effcc6eb7074a79443a2778ded46e58b274e00f3605 |