Create Text Mask(CreateTextMask)
This node creates a canvas and renders text based on the Pillow image library.
Create Text Mask
The Create Text Mask node creates a canvas and renders text based on the Pillow imaging library.
The Create Text Mask node is used to generate an image containing specified text and its corresponding mask. It allows users to customize text content, font, color, position, and size, and outputs a transparent background text layer and mask that can be used in subsequent image processing workflows.
Node Functionality
This node creates a canvas and renders text based on the Pillow imaging library. It supports loading TrueType font files from a specific folder and can generate single-frame images or create multi-frame rotation animation sequences by setting start and end rotation angles. The output image and mask formats are compatible with ComfyUI's standard IMAGE and MASK data types.
Node Parameter Description - Create Text Mask
Inputs
| Parameter Name | Data Type | Required | Default Value | Range/Options | Description |
|---|---|---|---|---|---|
font | COMBO | Yes | - | - | Select the font file to use from the specified font folder. |
invert | BOOLEAN | Yes | False | - | Invert the mask area, swapping the mask values of the text area and the background area. |
frames | INT | Yes | 1 | 1 - 4096 (step: 1) | Specify the number of frames for the generated image or animation. |
text_x | INT | Yes | 0 | 0 - 4096 (step: 1) | Set the horizontal starting position (X coordinate) of the text on the canvas. |
text_y | INT | Yes | 0 | 0 - 4096 (step: 1) | Set the vertical starting position (Y coordinate) of the text on the canvas. |
font_size | INT | Yes | 32 | 8 - 4096 (step: 1) | Set the font size of the text. |
font_color | STRING | Yes | white | - | Set the color of the text, represented by a color name (e.g., "white") or a hexadecimal value (e.g., "#FFFFFF"). |
text | STRING | Yes | HELLO! | - | Input the text content to be rendered, supporting multi-line text. |
width | INT | Yes | 512 | 16 - 4096 (step: 1) | Set the width of the generated image. |
height | INT | Yes | 512 | 16 - 4096 (step: 1) | Set the height of the generated image. |
start_rotation | INT | Yes | 0 | 0 - 359 (step: 1) | Set the starting rotation angle of the text (first frame only). |
end_rotation | INT | Yes | 0 | -359 - 359 (step: 1) | Set the ending rotation angle of the text (last frame). |
Output
| Parameter Name | Data Type | Description |
|---|---|---|
| IMAGE | IMAGE | Outputs the rendered text image with a transparent background. |
| MASK | MASK | Outputs the black-and-white mask corresponding to the text image. |
Usage Scenarios
This node is very useful when creating text titles, adding watermarks to images, or creating workflows that require text-shaped masks for inpainting. For example, you can first generate a text mask and then connect it to a "VAE Encode" or "Image Composite" node to control the precise area for text-to-image generation or local inpainting.
Notes
Please note that font files need to be placed in the ComfyUI/custom_nodes/ComfyUI-KJNodes/fonts directory in advance for the node to recognize and load them properly. The generated image dimensions are limited by the width and height parameters, with a maximum of 4096x4096.
Create Text Mask Node Source Code Link
The Create Text Mask node is from the ComfyUI-KJNodes node package.
Comments
Sign in with GitHub to join the discussion.