Persian Text Generator
Persian and Arabic text in ComfyUI that actually connects its letters
- IMAGE
- MASK
What it is
Diffusion models mangle text on posters - that's a given - but the standard fix, rendering text separately and compositing it, quietly falls apart for Persian and Arabic. Vanilla Pillow and most ComfyUI text nodes draw Arabic-script text as disconnected, left-to-right letters. That's not a style choice; it's missing bidi handling. PersianText is the node that fixes it: a pure-Python text renderer that draws Farsi, Arabic, and English with real letter joining and right-to-left layout, then hands you an IMAGE and a MASK you can drop straight into your workflow.
No model, no API key, no GPU work. It's Pillow doing honest typography, and it's genuinely the thing to reach for when your poster needs Persian, Arabic, or a Farsi-plus-English mix that renders correctly the first time. You'll find it under 🎨KG.
How it works
The whole trick is Unicode bidi handling. The node walks your text character by character and classifies each glyph's script from Unicode bidi data. Arabic-script runs go through arabic_reshaper (which joins letters into their cursive forms) and then python-bidi's get_display() (which does the RTL reordering). Latin runs pass through untouched. On a mixed line, it splits into per-script segments, lays them out on the fly, and draws each with its own font - which is exactly why there are two separate font dropdowns.
From there it's classic Pillow: text gets drawn onto a grayscale mask layer, an optional shadow is pasted behind it with Gaussian blur, everything composites together, and rotation spins in place around the text's own center without resizing the canvas. Both outputs come from the same pass, so the MASK always lines up with the IMAGE pixel for pixel.
The inputs that matter
- Text - multiline, and it supports dynamic prompts, so you can randomize poster copy across a batch.
- Farsi/Arabic Font and English/Latin Font - dropdowns populated from the
Fontsfolder. Drop any.ttfor.otfin there and it appears after a restart. - Size, Horizontal/Vertical Align, Offset X/Y, Rotation - the standard layout knobs.
- Colors - a 30-color palette, or pick "Custom (HEX Color)" and fill the matching hex field. v2 made hex input forgiving, so
#is optional. - Image Width / Image Height, Padding, Transparent Background - canvas control up to 4096px.
One trap worth knowing: the "default" option in the font dropdown silently resolves to arial.ttf (I checked the source), and Arial has zero Arabic glyphs. Pick a bundled Persian font - BYekan, BZar, or BYagut - or your text comes out as boxes.
Outputs: IMAGE (RGBA tensor) and MASK (grayscale). Save the image, composite it over a generation, or feed the mask into an inpainting or compositing branch.
Install
Easiest via ComfyUI Manager - search "PersianText". Or:
cd ComfyUI/custom_nodes
git clone https://github.com/shahkoorosh/ComfyUI-PersianText.git
cd ComfyUI-PersianText
pip install -r requirements.txt
Restart after. No model files to download - the repo ships Arial plus three Persian fonts.
The one real headache is python-bidi: it ships a C extension that frequently fails to build inside ComfyUI's embedded Python on Windows. The README's second half is a whole three-option guide to this exact failure, which tells you how common it is. If you see ModuleNotFoundError: No module named 'bidi.bidi', the extension didn't compile - install Microsoft's Visual C++ Build Tools and reinstall, or skip the compiler entirely and grab a prebuilt wheel from PyPI matching your Python version (for Python 3.10 on 64-bit Windows, that's python_bidi-0.6.6-cp310-cp310-win_amd64.whl). arabic-reshaper is pure Python and never fights you.
Common issues
The bidi install failure above is far and away the most reported problem. After that, boxes instead of letters almost always means the font lacks the glyphs - see the "default" trap above. And if you're mixing scripts in a single line, keep the line reasonable; the per-segment layout is clever, but a long run of alternating Farsi and English can get fiddly with alignment. Everything else - colors, shadows, rotation - behaves like you'd expect.
Inputs (21)
| Name | Type | Default | Description |
|---|---|---|---|
| Text | STRING | سلام کامفی | — |
| Farsi/Arabic Font | COMBO | BYekan.ttf | 5 options: default, BZar.ttf, BYagut.ttf, arial.ttf, BYekan.ttf |
| English/Latin Font | COMBO | arial.ttf | 5 options: default, BZar.ttf, BYagut.ttf, arial.ttf, BYekan.ttf |
| Size | INT | 601–256 | — |
| Text Color | COMBO | Black | 30 options: Custom (HEX Color), White, Black, Aqua, Blue, Brown, +24 |
| Background Color | COMBO | White | 30 options: Custom (HEX Color), White, Black, Aqua, Blue, Brown, +24 |
| Horizontal Align | COMBO | center | 3 options: left, center, right |
| Vertical Align | COMBO | center | 3 options: top, center, bottom |
| Image Width | INT | 5121–4096 | — |
| Image Height | INT | 5121–4096 | — |
| Rotation | FLOAT | 0.00-360–360 | — |
| Offset X | INT | 0-256–256 | — |
| Offset Y | INT | 0-256–256 | — |
| Shadow Distance | FLOAT | 0.000–256 | — |
| Shadow Blur | FLOAT | 0.000–256 | — |
| Shadow Color | COMBO | Black | 30 options: Custom (HEX Color), White, Black, Aqua, Blue, Brown, +24 |
| Text Color Hex | STRING | #000000 | — |
| Background Color Hex | STRING | #FFFFFF | — |
| Shadow Color Hex | STRING | #000000 | — |
| Padding | INT | 00–256 | — |
| Transparent Background | BOOLEAN | false | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |