This plugin provides a way to draw text boxes on images via a Thumbor filter.
Compatible with Thumbor 7.x (Python 3.10+).
pip install thumbor_text_filter
Add thumbor_text_filter to FILTERS in thumbor.conf, for example:
FILTERS = [
# other filters....
'thumbor_text_filter',
]Add text() to the filters section of a thumbor url. The method signature is:
text(word, x, y, color, font-size, font-family, box-color, box-width, box-height)
-
word,x,y,color,font-sizeare required. -
wordmay be plain text, or url-safe base64 prefixed withbase64:. Use the base64 form when the text contains characters that would break the url, such as commas (which separate filter arguments). Padding (=) may be omitted. -
font-familyis optional (defaults toDejaVuSans.ttf). It accepts, in order of resolution:- a font file name or path (e.g.
LiberationSerif-Bold,DejaVuSans.ttf,/usr/share/fonts/.../MyFont.ttf); - a family name (e.g.
Arial,Times New Roman) resolved to the closest installed font via fontconfig (fc-match), when available; - otherwise Pillow's bundled default font is used.
Note: family-name resolution needs
fontconfiginstalled on the host (standard on most Linux distros). Usefc-list : fileto see what is available. Values with spaces must be url-encoded (e.g.Times%20New%20Roman). - a font file name or path (e.g.
-
box-color,box-width,box-heightare optional. When all three are provided, a solid-colour box ofbox-widthxbox-heightis drawn at(x, y)and the text is centered inside it. If any of them is missing, the text is drawn as plain text anchored at its top-left(x, y)corner.
For color and box-color, see the available color names here:
https://pillow.readthedocs.io/en/stable/reference/ImageColor.html#color-names
Examples:
# plain text
http://thumbor/unsafe/filters:text(hello,10,10,red,25)/your-image-url
http://thumbor/unsafe/filters:text(hello,10,10,red,25,Arial)/your-image-url
# white text centered on a solid blue 200x60 box at (10,10)
http://thumbor/unsafe/filters:text(hello,10,10,white,25,Tahoma,blue,200,60)/your-image-url
# base64-encoded text (here "hola, mundo") to allow commas and other chars
http://thumbor/unsafe/filters:text(base64:aG9sYSwgbXVuZG8,10,10,red,25)/your-image-url
This project is managed with uv.
uv sync # create the environment and install dependencies
uv run pytest # run the test suite
MIT