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
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 Usage
from PIL import Image
from imagetext_py import *
font = Font("coolvetica.ttf", fallbacks=["emojis.ttf", "japanese.otf"])
black = Paint.Color((0, 0, 0, 255))
rainbow = Paint.Rainbow((0.0,0.0), (256.0,256.0))
# images must be converted to RGBA
im = Image.open("unknown.png").convert("RGBA")
# note: drawing operations are only applied after the context manager exits
with Writer(im) as w:
w.draw_text_wrapped(
text="hello my 😓 n🐢ame i☕s 会のすべ aての構成員 nathan and i drink soup boop coop, the quick brown fox jumps over the lazy dog",
x=256, y=256,
ax=0.5, ay=0.5,
width=512,
size=67,
font=font,
fill=black,
align=TextAlign.Center,
stroke=2.0,
stroke_color=rainbow
)
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 Distribution
imagetext_py-1.0.2.tar.gz
(25.7 kB
view hashes)
Built Distributions
Close
Hashes for imagetext_py-1.0.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 178e45be6f0715e736d9b61d10ad291038f5d5802f01f495c6e47b7cb88ab1a5 |
|
MD5 | 4f380b5c9cc1754dd26da73a910edc27 |
|
BLAKE2b-256 | 72d906f22f23ad3e47239741063518df7baacdabcde8a3e82a0c57d00067b5a7 |
Close
Hashes for imagetext_py-1.0.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaf54712b4b8a295623d0aa8703fb5462e1a4256dbb8c65245ef15a28085f711 |
|
MD5 | 44fa404fc94dd5a1a6ecc6c35863a4c7 |
|
BLAKE2b-256 | 34c8e0ceafdd96940475ee2215113468b3851df6f2b94346cde3f894de477b42 |
Close
Hashes for imagetext_py-1.0.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5639785bacd32fbd9339af16b8e5357d3912ff5d9a1bfa1ea6bd3d4ca2cf594 |
|
MD5 | 337f1df553959bb68084c84c818528d5 |
|
BLAKE2b-256 | 536d4518b645aea1e55fc2bf9cc57be39891c8df99942561427b1c3fb57cf278 |
Close
Hashes for imagetext_py-1.0.2-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47cae08510a105d10f8cf8f0c8a073745c53f7e6e4c57f9acaa3e605a6f8fe58 |
|
MD5 | f095ce26b5cdbc30e677e8820276059b |
|
BLAKE2b-256 | 7a98c1411a8a858b96f99efc7c491fa4baf73cc6af6911515b3e9aa40a6bfaaa |
Close
Hashes for imagetext_py-1.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01553f0c741c97e231b0cdd386d726afa224c5c34b2bd8ddaa7b57133b77014a |
|
MD5 | 1cc386758bd28bb7c8316851614146a3 |
|
BLAKE2b-256 | ec2dbafcaf65014123a27e90270ba2d277c0defacf37ff04651f52f56221b636 |
Close
Hashes for imagetext_py-1.0.2-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | baf6c56a6407fa0c20186e817d90468b8ec5b508db831bd0ec94b88faa77dda9 |
|
MD5 | cae1025bf32b4f0b4e5e4461ccfc7e4c |
|
BLAKE2b-256 | 6bf27dedc0a28190910e8dbf2280d98e38907d030cc0ddfd3fd0541aafff3074 |
Close
Hashes for imagetext_py-1.0.2-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66646682b3c1ee0078807ac6d8439263cd8c3d7e7011d132aecfd40cb623b5a5 |
|
MD5 | 24cd40e7343e721c9579652dcca56386 |
|
BLAKE2b-256 | f0593ad039fe880c053b04fdf5d00b72ac4fd7e45ae8341d118463e3ec552703 |
Close
Hashes for imagetext_py-1.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b2429446fa9c42192b7b64faffec44d34643021fc8a93773b0892edc6d925e9 |
|
MD5 | 99ebb3604f6fe39816cc78736bf5c040 |
|
BLAKE2b-256 | 5c77b9b2b28b85a9300117035bfee787a1e53e9ab02f619458717e2634d738d1 |
Close
Hashes for imagetext_py-1.0.2-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a910235effc499e0c632ba5efb026e74280fe50b5790bd5f207324593c612fa4 |
|
MD5 | e7075f94d3307d56656e6a92624d3c9b |
|
BLAKE2b-256 | f455d6dcedaef12e2f184997363b86a306e19d5b60f1863a4ff477b7b5b54c80 |
Close
Hashes for imagetext_py-1.0.2-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8958b4a9e692cdc15f39df1270cc02dc3fd734a32259311e84b3bdf142a2f148 |
|
MD5 | 6e233923a5d4da5506120439611f09ce |
|
BLAKE2b-256 | a7576cc6023e9707adcac2209840aa859e9c3895d44f9f2e2a80f3e20c312c02 |
Close
Hashes for imagetext_py-1.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13bf7334cdbb3ed5b5ac10794cd4c3b302e1448ceb1461aec2d93036e0906f0f |
|
MD5 | 365872cbb38873ca9b786b274bc4c204 |
|
BLAKE2b-256 | 133872cc1ecc3b3588cb01524b4911a2e79528f16529aa2ea29c48361e52ea0e |
Close
Hashes for imagetext_py-1.0.2-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d807301b6d7b2dc85b512718790a89c487b6d0f7e4d888fa948bc263d5f70bfb |
|
MD5 | 5836beea71460a6f2c72bff56fd9ff7d |
|
BLAKE2b-256 | 4609687e6b3a1afeb27a066429d2483a614f9f3473378193cecd78cc9a071232 |
Close
Hashes for imagetext_py-1.0.2-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2a81f1a416e25cc8e131fc218e69f96b5a2688c189576a77c264e9596b6faa2 |
|
MD5 | 105ae0c305d2164e3a7603f237048b84 |
|
BLAKE2b-256 | 41dd470cdf394c0851c7884f394e1782ddbcffad39ee3ad5aa1c213be8b15239 |
Close
Hashes for imagetext_py-1.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24b397736a34984d71e070c866b1239fd47192654d8e597eabc679cf9c3fdb7a |
|
MD5 | 183beca2eec262002aeda7d1a478762d |
|
BLAKE2b-256 | 064d2b2700fd01f249d370b67f5ef7089c35db29228344d78ea0fc244464f295 |
Close
Hashes for imagetext_py-1.0.2-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6428f2720df3ca9ebfe408064848e3694fead9b15b6fbaa6bc891457531ef401 |
|
MD5 | 83627cd70c3f48c5f0c658ef946789d5 |
|
BLAKE2b-256 | 73c0c2b0ff3b5659d91be52e1e041983345e0779c5cd908b66958683e3d47d05 |
Close
Hashes for imagetext_py-1.0.2-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5aa0ae20d1d26d9de1b690ae99da80cbcafcad264c93137b8d3f9911b12f60d8 |
|
MD5 | 4c446c6063dbd61077ae7759e1c86690 |
|
BLAKE2b-256 | d022b420858fd780ff2e4e09c7def660ab1482347b24bb0997ec9a70b6283ade |
Close
Hashes for imagetext_py-1.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 848d08caf39c13bcc224f9ec656e9081c61087be04d7f9b6fd979928ebde9045 |
|
MD5 | ea21b7f568fde892e6956d92889224bb |
|
BLAKE2b-256 | 772292b0e48b9a649c577f0e2869fb36195209b126b8bc1172c70fcef657401c |
Close
Hashes for imagetext_py-1.0.2-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da16c55b80b5f36decb92cfcd5a017087e50be54906b3d4c1498a45e2292cff6 |
|
MD5 | b59437e7c8dff09be4a338ce5133a6a8 |
|
BLAKE2b-256 | 3bb51ac5eee0bd901c17eb0d0f70b3f77882aa4b8a8409d4ebc867fd09731cb1 |