Nodes/ComfyUI-PersianText/Persian Text Generator
ComfyUI Node

Persian Text Generator

Persian and Arabic text in ComfyUI that actually connects its letters

By shahkoorosh·Created 2 years ago·Updated about a year ago· 30
Persian Text Generator
    • IMAGE
    • MASK
    Textسلام کامفی
    Farsi/Arabic FontBYekan.ttf
    English/Latin Fontarial.ttf
    Size60
    Text ColorBlack
    Background ColorWhite
    Horizontal Aligncenter
    Vertical Aligncenter
    Image Width512
    Image Height512
    Rotation0.00
    Offset X0
    Offset Y0
    Shadow Distance0.00
    Shadow Blur0.00
    Shadow ColorBlack
    Text Color Hex#000000
    Background Color Hex#FFFFFF
    Shadow Color Hex#000000
    Padding0
    Transparent Backgroundfalse

    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 Fonts folder. Drop any .ttf or .otf in 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.

    Category🎨KG

    Inputs (21)

    NameTypeDefaultDescription
    TextSTRINGسلام کامفی
    Farsi/Arabic FontCOMBOBYekan.ttf5 options: default, BZar.ttf, BYagut.ttf, arial.ttf, BYekan.ttf
    English/Latin FontCOMBOarial.ttf5 options: default, BZar.ttf, BYagut.ttf, arial.ttf, BYekan.ttf
    SizeINT601–256
    Text ColorCOMBOBlack30 options: Custom (HEX Color), White, Black, Aqua, Blue, Brown, +24
    Background ColorCOMBOWhite30 options: Custom (HEX Color), White, Black, Aqua, Blue, Brown, +24
    Horizontal AlignCOMBOcenter3 options: left, center, right
    Vertical AlignCOMBOcenter3 options: top, center, bottom
    Image WidthINT5121–4096
    Image HeightINT5121–4096
    RotationFLOAT0.00-360–360
    Offset XINT0-256–256
    Offset YINT0-256–256
    Shadow DistanceFLOAT0.000–256
    Shadow BlurFLOAT0.000–256
    Shadow ColorCOMBOBlack30 options: Custom (HEX Color), White, Black, Aqua, Blue, Brown, +24
    Text Color HexSTRING#000000
    Background Color HexSTRING#FFFFFF
    Shadow Color HexSTRING#000000
    PaddingINT00–256
    Transparent BackgroundBOOLEANfalse

    Outputs (2)

    NameTypeDescription
    IMAGEIMAGE
    MASKMASK