Nodes/😸 YFG Comical Nodes/🐯 YFG Text Mask Overlay
ComfyUI Node

🐯 YFG Text Mask Overlay

Stamp text onto a mask β€” the node for watermarks and annotations

By gonzaluΒ·Created 2 years agoΒ·Updated a day agoΒ· 29
🐯 YFG Text Mask Overlay
  • mask
  • mask
  • image
β—„font_sourceβ–Ύβ–Ί
β—„system_fontimpact.ttfβ–Ί
β—„node_fontmalgunbd.ttfβ–Ί
β—„usr_font_dir%LocalAppData%\Microsoft\Windows\Fontsβ–Ί
β—„directory_fontNo fonts available in specified directoryβ–Ί
β—„textTEXTβ–Ί

Want to burn a word onto an image - a watermark, a caption, a comic-speech-bubble effect - and do it cleanly, right in the graph? The standard route is a text-to-image node plus a pile of masking nodes to get the letters placed. This node collapses that into one box: give it a MASK and a string, and it carves the text into the mask for you, then hands you both the edited mask and a ready-to-composite image. It's the "Text Mask Overlay" node from the YFG Comical pack (gonzalu/ComfyUI_YFG_Comical), an enhanced take on Yuigahama Yui's ComfyUI-Text idea.

How it works

The mechanism is clever and simple at once. It runs cv2.findContours on your input mask, finds the largest blob, and treats its bounding box as the canvas for your text. Then it auto-fits the string: it computes how many rows the box can hold (1–3 based on aspect ratio), picks a font size from the box width, and draws the text in white inside the contour's area. The result is a new mask - the text area is white, everything else black - plus an RGB image version of that mask, so you can composite it with a Blend/Composite node without an extra mask-to-image converter.

mask is the required input, and it's worth knowing the node keys off your mask's biggest region. If your mask has one big subject blob, text lands there; a mask with scattered specks will put the text on the largest speck. For predictable placement, feed it a mask where the region you want to label is the dominant one.

Fonts

font_source picks where the typeface comes from:

  • System - fonts installed on your OS (via system_font).
  • Node Folder - the pack ships 17 fonts in its fonts/ directory (impact.ttf, PixelifySans-Bold, YoungSerif-Regular, Roboto, comic.ttf, and more). This is the easiest path - no setup, just pick one.
  • Directory - any folder you point at via usr_font_dir (defaults to the Windows %LocalAppData%\...\Fonts path; change it to a local folder on Linux/Mac).

Outputs

  • mask (MASK) - the original mask with text carved in. Wire this into a KSampler's mask for inpainting, or into compositing.
  • image (IMAGE) - the mask rendered as an image, so you can multiply/overlay it directly.

Installing

Pack install, as always: ComfyUI Manager β†’ search "YFG Comical", or

cd ComfyUI/custom_nodes
git clone https://github.com/gonzalu/ComfyUI_YFG_Comical

Restart ComfyUI. This node needs cv2 (opencv-python) - another case of the pack importing it without declaring it in pyproject.toml. If the pack fails to import, pip install opencv-python matplotlib and restart.

The honest take

This is the pack's nicest "actually useful" utility - watermarking is a pain in stock ComfyUI, and this makes it a two-node job (this + a composite). Two caveats: the auto-fit means long strings get tiny, so keep the text short, and the output mask is a hard white-on-black cutout with no anti-aliasing - if you want soft-edged letters, blur the mask after. For a quick "sign your render" node, it's genuinely hard to beat.

Category🐯 YFG

Inputs (7)

NameTypeDefaultDescription
font_sourceCOMBO3 options: System, Node Folder, Directory
system_fontCOMBOimpact.ttf1 options: fonts-japanese-gothic.ttf
node_fontCOMBOmalgunbd.ttf17 options: YoungSerif-Regular.ttf, malgunbd.ttf, impact.ttf, Oswald-Bold.ttf, HothamFreeDemo-L380G.ttf, PixelifySans-Bold.ttf, +11
usr_font_dirSTRING%LocalAppData%\Microsoft\Windows\Fontsβ€”
directory_fontCOMBONo fonts available in specified directory1 options: No fonts available in specified directory
textSTRINGTEXTβ€”
maskMASKβ€”

Outputs (2)

NameTypeDescription
maskMASKβ€”
imageIMAGEβ€”