KJNodes/textgenerated

Add Label(AddLabel)

From a technical implementation perspective, this node uses the PIL library for image processing and text rendering.

Add Label

image
IMAGE
text_x
10
text_y
2
height
48
font_size
32
font_color
white
label_color
black
font
COMBO
text
Text
direction
up
caption
STRING
KJNodes

From a technical implementation perspective, the Add Label node utilizes the PIL library for image processing and text rendering.

The Add Label node is an image annotation tool that adds a label strip containing custom text onto an input image. Its core functionality is to generate a background area with text and then stitch or overlay it onto the original image, thereby adding descriptive text to the image.

Node Functionality

From a technical implementation perspective, this node uses the PIL library for image processing and text rendering. It supports stitching the label strip to the "top, bottom, left, or right" edges of the image, or overlaying it directly onto the image in "overlay" mode. The node loads font files from a specified font folder (typically ComfyUI/custom_nodes/ComfyUI-KJNodes/fonts) and allows users to define the text and label background colors using color strings (e.g., "white", "#FF0000").

Node Parameter Description - Add Label

Connection Inputs (Inputs)

Parameter NameData TypeRequiredDefault ValueValue Range/OptionsDescription
imageIMAGEYes--image (Input Parameter): The original image to which the label needs to be added.
fontCOMBOYes-(List of available fonts)font (Input Parameter): Select the font file used for rendering the text. The font file must be placed in the specified kjnodes_fonts directory.

Control Parameters (Parameters)

Parameter NameData TypeRequiredDefault ValueValue Range/OptionsDescription
directionCOMBOYesup"up", "down", "left", "right", "overlay"down (bottom), left (left side), right (right side), or overlay (directly overlaid on the image).
text_xINTYes100 - 4096 (Step: 1)text_x (Input Parameter): Sets the horizontal starting position (X coordinate) of the label text within the label strip. Value range is 0 to 4096.
text_yINTYes20 - 4096 (Step: 1)text_y (Input Parameter): Sets the vertical starting position (Y coordinate) of the label text within the label strip. Value range is 0 to 4096.
heightINTYes48-1 - 4096 (Step: 1)height (Input Parameter): Sets the height of the label strip (when the direction is left or right, this parameter controls the width). When the value is -1, the height will automatically adapt to the font size.
font_sizeINTYes320 - 4096 (Step: 1)font_size (Input Parameter): Sets the font size of the label text. Value range is 0 to 4096.
font_colorSTRINGYeswhite-font_color (Input Parameter): Defines the color of the label text. Supports color names (e.g., "white") or hexadecimal color codes (e.g., "#FF0000").
label_colorSTRINGYesblack-label_color (Input Parameter): Defines the background color of the label strip. Supports color names (e.g., "black") or hexadecimal color codes.
textSTRINGYesText-text (Input Parameter): Input the text content to be displayed on the label strip.
captionSTRINGNo""-caption (Input Parameter): Optional additional caption text.

Output

Parameter NameData TypeDescription
IMAGEIMAGEIMAGE (Output Parameter): Outputs the image with the text label added.

Usage Scenarios

This node is very practical in image batch processing or generation workflows. For example, after generating a series of style test images, you can use this node to automatically add a label to each image describing its parameters (such as model name, sampling steps), facilitating subsequent comparison and filtering. It can also be used to add dialogue text or sequence numbers to comic panels or storyboard images.

Notes

It is important to note that when selecting the "top, bottom, left, right" directions, this operation will change the dimensions (height or width) of the output image. Additionally, font color and label background color support various formats, but it is necessary to ensure that the input string can be correctly parsed as an RGB color value.

The Add Label node is from the ComfyUI-KJNodes node package.

Comments

Sign in with GitHub to join the discussion.

Loading comments…