Nodes/ComfyUI-YCNodes/YC Text Image Generator
ComfyUI Node

YC Text Image Generator

Render text to an image (and its mask) without ever leaving ComfyUI

By yichengup·Created 2 years ago·Updated 4 months ago· 48
YC Text Image Generator
  • background_color
  • text_color
  • IMAGE
  • MASK
text示例文本 Sample Text
canvas_width512
canvas_height512
font_size72
orientationhorizontal
alignmentcenter
vertical_alignmentmiddle
x_position0
y_position0
background_alpha1.00
text_alpha1.00
font
letter_spacing0.00
word_spacing1.0
line_spacing1.2

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 - horizontal or vertical; 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.

CategoryYCNode/Text

Inputs (17)

NameTypeDefaultDescription
textSTRING示例文本 Sample Text
canvas_widthINT51264–4096
canvas_heightINT51264–4096
font_sizeINT728–500
orientationCOMBOhorizontal2 options: horizontal, vertical
alignmentCOMBOcenter3 options: left, center, right
vertical_alignmentCOMBOmiddle3 options: top, middle, bottom
x_positionINT0-4096–4096
y_positionINT0-4096–4096
background_colorCOLOR#000000
text_colorCOLOR#ffffff
background_alphaFLOAT1.000–1
text_alphaFLOAT1.000–1
fontCOMBO1 options: alcatraz+script.otf
letter_spacingFLOAT0.00-0.5–2
word_spacingFLOAT1.00.5–5
line_spacingFLOAT1.20.5–3

Outputs (2)

NameTypeDescription
IMAGEIMAGE
MASKMASK