YC Text Image Generator
Render text to an image (and its mask) without ever leaving ComfyUI
- background_color
- text_color
- IMAGE
- MASK
Sometimes you need actual words in an image pipeline, not just words about the image. Titles, watermarks, styled labels, or a text region you intend to outpaint or inpaint into - all of those are annoying to produce outside ComfyUI because you'd have to save a PNG, bring it back in, and hope the canvas lines up. YCTextImageGenerator does it in-graph: it renders your text onto a canvas and hands back both the image and a matching mask, so you can composite the text cleanly or use the mask to tell a model exactly where the text lives.
How it works
The node draws your text with PIL onto an RGBA canvas, then generates a second, mask-style image (black background, white text) from the same layout. Because both come from one layout pass, the mask is pixel-aligned with the glyphs by construction - no manual alignment, no "close enough." It handles multi-line input, horizontal or vertical orientation, and gives you the full typography toolbox: font size, alignment, vertical position, letter and line spacing, plus independent colors and alpha for text and background. Chinese and English both work, which matters if you're rendering anything bilingual.
The font dropdown is driven by whatever .ttf/.otf files live in the pack's font/ folder - the pack ships exactly one font, the script-style alcatraz+script.otf, so out of the box you get a single decorative option. Drop more fonts in and restart, and they appear in the list.
The inputs that matter
- text - multiline. Each line becomes a text line (respecting
line_spacing). - canvas_width / canvas_height - canvas in pixels (64–4096, step 8). Text is positioned within this box, so bigger canvas means more room, not bigger text.
- font_size - 8–500, default 72.
- orientation -
horizontalorvertical; vertical is handy for Asian-style titles or narrow banners. - background_color / text_color - hex colors; background_alpha / text_alpha control transparency for each.
- font - the font file to use.
Outputs are IMAGE and MASK, both full-canvas. Composite the IMAGE onto a photo using the MASK as the blend region, or feed the MASK to an inpaint/controlnet stack to "erase" or regenerate the text area.
Installing it
Part of ComfyUI-YCNodes. ComfyUI Manager → search ComfyUI-YCNodes → install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/yichengup/ComfyUI-YCNodes
Restart, then look under YCNode/Text. Dependencies are the pack's usual torch, numpy, pillow, opencv-python, scipy - PIL is doing the heavy lifting here.
Gotchas
The single font is the thing people hit first: the dropdown shows alcatraz+script.otf and nothing else, so any serious use means adding fonts to the pack's font/ directory (a system font like NotoSans or Inter works) and restarting ComfyUI. Also note the mask is the text shape on black - black canvas, white glyphs - which is the convention mask nodes expect, but it's the opposite of a "text as background" mask. If your composite looks inverted, flip the mask or blend accordingly. And don't expect WYSIWYG alignment: x_position/y_position are raw pixel offsets, so you'll do one calibration pass and then it's fine.
Inputs (17)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | 示例文本 Sample Text | — |
| canvas_width | INT | 51264–4096 | — |
| canvas_height | INT | 51264–4096 | — |
| font_size | INT | 728–500 | — |
| orientation | COMBO | horizontal | 2 options: horizontal, vertical |
| alignment | COMBO | center | 3 options: left, center, right |
| vertical_alignment | COMBO | middle | 3 options: top, middle, bottom |
| x_position | INT | 0-4096–4096 | — |
| y_position | INT | 0-4096–4096 | — |
| background_color | COLOR | #000000 | — |
| text_color | COLOR | #ffffff | — |
| background_alpha | FLOAT | 1.000–1 | — |
| text_alpha | FLOAT | 1.000–1 | — |
| font | COMBO | 1 options: alcatraz+script.otf | |
| letter_spacing | FLOAT | 0.00-0.5–2 | — |
| word_spacing | FLOAT | 1.00.5–5 | — |
| line_spacing | FLOAT | 1.20.5–3 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |