π― YFG Text Mask Overlay
Stamp text onto a mask β the node for watermarks and annotations
- mask
- mask
- image
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%\...\Fontspath; 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.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| font_source | COMBO | 3 options: System, Node Folder, Directory | |
| system_font | COMBO | impact.ttf | 1 options: fonts-japanese-gothic.ttf |
| node_font | COMBO | malgunbd.ttf | 17 options: YoungSerif-Regular.ttf, malgunbd.ttf, impact.ttf, Oswald-Bold.ttf, HothamFreeDemo-L380G.ttf, PixelifySans-Bold.ttf, +11 |
| usr_font_dir | STRING | %LocalAppData%\Microsoft\Windows\Fonts | β |
| directory_font | COMBO | No fonts available in specified directory | 1 options: No fonts available in specified directory |
| text | STRING | TEXT | β |
| mask | MASK | β |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| mask | MASK | β |
| image | IMAGE | β |