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.
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
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distributions
Close
Hashes for imagetext_py-2.1.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b913f681efd30bbf6e813995d95b20fc740373981bb0d72d5b3298dc0eb2fb0 |
|
MD5 | f0c30d76384eff75b1eddd9774c056a0 |
|
BLAKE2b-256 | d23f6fac8e014ab6a50f93c9d4c0bc3227af93f5f1bab9389f0131ff4fcba9cd |
Close
Hashes for imagetext_py-2.1.1-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bed7a6688ac8a29b729d80453d70e3a5d59644677ddafc67a876249e3ed307a |
|
MD5 | 306ad731edd93e10b6859b5b558f9410 |
|
BLAKE2b-256 | d3d731ba49033495a28fb83a9c1aa649623d1a86046c0c101dd8de33bff4f911 |
Close
Hashes for imagetext_py-2.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53f295f6c627b34c85809358886d00d144ec31a6679198febc02869297f6ecde |
|
MD5 | a9671c35f0d9bd8d69a974ec2be0b5df |
|
BLAKE2b-256 | c47bef565d6a0acf393a03dc22f60746f5a76e068a5406572f973a1d426ad1a3 |
Close
Hashes for imagetext_py-2.1.1-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e7de7e120cd1c26d70ebd039fff30be7caa109ccc40a02df03bcb1c176398bf |
|
MD5 | fd946b71fc3696d3b6183eb6b6dcfac9 |
|
BLAKE2b-256 | a97395f7c139f804b320b3c737dc58c7c825c3e4ec4c08dc395629745484fdca |
Close
Hashes for imagetext_py-2.1.1-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb8f102de00f0df51b3f3f5a1e810633c66312b2880604167463399770a061d3 |
|
MD5 | edd3944d99c421196685e77df1e65e42 |
|
BLAKE2b-256 | 60a536de35454fb495530f30af49e94d98d9cc3ab87e2334ac452355a312b73e |
Close
Hashes for imagetext_py-2.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f878f27edbef11f774e60cb2f3369e17849c7c4235bbacb485381eacf7e9c3ab |
|
MD5 | c0fab48efcddcff5c92fef62bc65aa16 |
|
BLAKE2b-256 | b7b802fbca120a50ef6c9ff1d4ea8bda00a4745323581d322f17f04fddd29fe9 |
Close
Hashes for imagetext_py-2.1.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8586bfffc4e6493e938fe1bb4a3357fbbfacbaa0c15531b86fce73c39be6f09e |
|
MD5 | 1108387c4b1eaab3e908df659f75271c |
|
BLAKE2b-256 | 9a4118a357d77340c8d5ad1e03ef846564e096b64426e11a8f2f1bd55beede59 |
Close
Hashes for imagetext_py-2.1.1-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c86c4225d0997bf553e562f5fc73fe9a85ec681e356b97baf080dcd2b5558cbe |
|
MD5 | 0ea4fb30cc7f62f9a6dba9b21fceb092 |
|
BLAKE2b-256 | a767ce29aec6a5778c8a37115b65faeaa7c838a4c62e20e0eca980dafaabc43d |
Close
Hashes for imagetext_py-2.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc69e57ad9342dcf8e7a39961276bf2c06472cb364db022a0a1e3c7627ca8ae9 |
|
MD5 | 7cafce31cd1258813fe218726f6875ca |
|
BLAKE2b-256 | 98869faf9538de47fadb1fff2d4b320c71338689ef72c929432b87e31d8d82c0 |
Close
Hashes for imagetext_py-2.1.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d818f912b7d19cf5745d661137465664f824e34d705b1b608513005d44d2b49c |
|
MD5 | 6d023708dcec5bc28147cdc3f65dd9b9 |
|
BLAKE2b-256 | d15d3ed22550dad8d033bc4970f87ccd2c12f7dbdf3a1ba552617848537e3932 |