ComfyUI S4Tool Text
Text rendering and styling nodes for ComfyUI. This extension provides a basic text renderer, multiple font loaders, and a style node that adds stroke, shadow, gradient fill, and opacity control.
Nodes (5)
The ComfyUI text node that can finally typeset CJK vertically
A whole font, pasted into one node, for when the workflow must travel
34 fonts bundled, including the CJK ones most text nodes forget
Pull any font from the internet without storing the file
Stroke, shadow, and gradient fill that don't look like trash
ComfyUI-S4Tool-Text · v1.0.0
Text rendering and styling nodes for ComfyUI. This extension provides a basic text renderer, multiple font loaders, and a style node that adds stroke, shadow, gradient fill, and opacity control. All nodes are grouped under the category "💀S4Tool" inside ComfyUI.
Highlights
- Horizontal and vertical typesetting, alignment, character spacing, and line spacing
- Multiple font sources: bundled file selector, Base64 string, and remote URL
- Style processing: scalable stroke (OpenCV SDF when available), drop shadow, gradient fill, and global alpha
- Outputs standard ComfyUI image tensors and masks
Requirements
- ComfyUI installed and running
- Python 3.10+ (match your ComfyUI environment)
- Dependencies:
# Required
pip install pillow numpy requests
# Optional (recommended for best stroke quality in the Style node)
pip install opencv-python
Notes:
- PyTorch is provided by ComfyUI; you typically do not need to install it manually for this extension.
Installation
- Place this folder at
ComfyUI/custom_nodes/ComfyUI-S4Tool-Text. - Start or restart ComfyUI.
- Nodes appear under the "💀S4Tool" category.
Nodes Overview
S4Tools Text Basic (py/textBasic.py)
Renders text into an RGBA image, and also exposes the rendered RGBA as "style" plus a grayscale mask.
- Inputs:
- font (
FONT_DATA): Font bytes (from one of the font loader nodes) - text (
STRING, multiline): Text content - font_size (
INT, 1–512, default 32) - color (
STRING, hex, default#000000) - text_direction (
horizontal|vertical, defaulthorizontal) - align (
left|center|right, defaultleft) - char_spacing (
INT, -50–200, default 0) - line_spacing (
FLOAT, -10.0–10.0, step 0.1, default 1.0)
- font (
- Outputs:
- image (
IMAGE): Tensor of the colored RGBA text on transparent background - style (
STYLE_DATA): The same RGBA image, convenient for downstream styling - mask (
MASK): Grayscale alpha mask of the text
- image (
Behavior notes:
- Horizontal mode:
line_spacingcontrols the gap between lines (as a multiple of font size). - Vertical mode: columns flow left-to-right;
line_spacingcontrols the horizontal gap between columns.
S4Tools Text Style (py/textStyle.py)
Applies stroke, outer shadow, gradient fill, and global alpha to an incoming style image.
- Inputs:
- style (
STYLE_DATA): RGBA style image (e.g., from Basic node outputstyle) - stroke_size (
INT, 0–100, default 0) - stroke_color (
STRING, hex, default#000000) - outer_shadow_x (
INT, -100–100, default 0) - outer_shadow_y (
INT, -100–100, default 0) - outer_shadow_color (
STRING, hex, default#000000) - outer_shadow_blur (
FLOAT, 0.0–20.0, step 0.1, default 2.0) - gradient_start (
STRING, hex, default#FFFFFF) - gradient_end (
STRING, hex, default#00FF00) - gradient_angle (
FLOAT, 0.0–360.0, default 0.0) - alpha (
FLOAT, 0.0–1.0, step 0.01, default 1.0)
- style (
- Outputs:
- IMAGE: Styled RGBA image tensor
- MASK: Final alpha mask
Quality notes:
- If
opencv-pythonis available, the node uses an SDF-like approach for smoother, scalable strokes. Otherwise, it falls back to a PIL-based stroke.
S4Tools Text Font file (py/textFontFile.py)
Loads font bytes from the bundled font/ directory.
- Inputs:
- font_name (enum): Populated from filenames in
font/(extension hidden). Supports.ttfand.otf.
- font_name (enum): Populated from filenames in
- Outputs:
- font (
FONT_DATA): Font bytes for downstream nodes
- font (
Notes:
- To add more fonts, copy
.ttfor.otffiles into thefont/folder. The selector lists names without extensions.
S4Tools Text Font Base64 (py/textFontBase64.py)
Decodes Base64-encoded font data (optionally accepts a data:*;base64, prefix).
- Inputs:
- font_base64 (
STRING, multiline)
- font_base64 (
- Outputs:
- font (
FONT_DATA)
- font (
Errors:
- Invalid input raises "Invalid base64 font data".
S4Tools Text Font URL (py/textFontURL.py)
Downloads a font file from a URL.
- Inputs:
- font_url (
STRING)
- font_url (
- Outputs:
- font (
FONT_DATA)
- font (
Dependencies:
- Requires
requestsat runtime.
Errors:
- Empty or failing downloads raise messages like "Unable to download font: ...".
Typical Workflow
- Choose a font source:
S4Tools Text Font filefor bundled fonts infont/S4Tools Text Font Base64to paste Base64 font dataS4Tools Text Font URLto fetch a remote font
- Connect the
fontoutput toS4Tools Text Basic→ configure text, sizing, spacing, and direction. - Optionally connect the
styleoutput intoS4Tools Text Stylefor stroke, shadow, and gradient. - View or save the resulting
IMAGEin ComfyUI.
Bundled Fonts
This repository ships multiple English and Simplified Chinese fonts inside the font/ directory. You can add or remove fonts by placing .ttf/.otf files there. The S4Tools Text Font file node will list them automatically by filename (without extension).
Error Handling Summary
- Base64 loader: raises on invalid Base64 content
- File loader: raises if the selected font file cannot be found
- URL loader: raises on network or HTTP errors
Changelog
- 1.0.0: Initial public release of the text nodes (Basic, Style, Font file, Font Base64, Font URL)