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 *
FontDB.LoadFromDir(".")
font = FontDB.Query("coolvetica japanese")
cv = Canvas(512, 512, (255, 255, 255, 255))
black = Paint.Color((0, 0, 0, 255))
rainbow = Paint.Rainbow((0.0,0.0), (256.0,256.0))
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,
text=text,
x=256, y=256,
ax=0.5, ay=0.5,
size=67,
width=500,
font=font,
fill=black,
align=TextAlign.Center,
stroke=2.0,
stroke_color=rainbow,
draw_emojis=True)
im: Image.Image = cv.to_image()
im.save("test.png")
dimensions, bytes = cv.to_bytes()
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:
