KJNodes/imagegenerated

Load & Resize Image(LoadAndResizeImage)

This node processes images based on the PIL library, supports common image formats, and can automatically correct EXIF orientation.

Load And Resize Image

image
mask
width
height
image_path
image
COMBO
resize
width
INT
height
INT
repeat
1
keep_proportion
divisible_by
2
mask_channel
COMBO
background_color
STRING
KJNodes

The Load & Resize Image node processes images based on the PIL library, supports common image formats, and can automatically correct EXIF orientation.

The Load & Resize Image node is a powerful tool for image loading and preprocessing. Its core functionality is to load images from ComfyUI's input directory and optionally resize them, process transparency channels, and generate masks, preparing them for subsequent image generation or editing workflows.

Node Functionality

This node processes images based on the PIL library, supports common image formats, and can automatically correct EXIF orientation. Its technical core lies in its ability to perform precise scaling and padding of images based on user-defined target dimensions and aspect ratio preservation options. Additionally, it can extract specified color channels (such as Alpha, Red, Green, Blue) as masks or fill transparent areas with a specified background color.

Node Parameter Description - Load & Resize Image

Connection Inputs (Inputs)

Parameter NameData TypeRequiredDescription
imageCOMBO (image list)YesSelect an image from ComfyUI's input directory. The widget lists available image files.
mask_channelCOMBOYesChannel to use for the mask output. Options include Alpha, Red, Green, Blue, and None.

Control Parameters (Parameters)

Parameter NameData TypeRequiredDefault ValueValue Range / OptionsDescription
resizeBOOLEANYesFalse-Whether to enable the image resizing function. When set to True, the image will be scaled according to subsequent parameters.
widthINTYes5120 – MAX_RESOLUTION (Step: 8)Target width for resizing (used only when resize is enabled).
heightINTYes5120 – MAX_RESOLUTION (Step: 8)Target height for resizing (used only when resize is enabled).
repeatINTYes11 – 4096 (Step: 1)Number of times the loaded image will be repeated along the batch dimension.
keep_proportionBOOLEANYesFalse-Whether to maintain the original aspect ratio of the image when resizing.
divisible_byINTYes20 – 512 (Step: 1)Aligns the resized image dimensions (width and height) to be integer multiples of this value.
background_colorSTRINGYes""-Fills transparent (Alpha) areas with the specified color. Accepts hex colors (e.g. #RRGGBB) or named colors.

Outputs

Parameter NameData TypeDescription
imageIMAGEThe processed image tensor (with transparency filled if background_color is specified).
maskMASKMask extracted from the chosen mask_channel.
widthINTActual width of the output image (after any resizing or proportion adjustments).
heightINTActual height of the output image.
image_pathSTRINGFile path of the loaded image.

Usage Scenarios

This node is very useful in workflows that require batch processing or uniform input image dimensions. For example, before starting an image-to-image workflow with Stable Diffusion, you can use this node to load a reference image, precisely scale it to the model's required 512x512 resolution, and simultaneously extract its Alpha channel as a mask to protect specific areas during repainting.

Notes

Please note that when keep_proportion (maintain proportion) is enabled, the actual output dimensions may not exactly match the set width and height. The system will adjust based on the original image's aspect ratio and the divisible_by parameter. Additionally, the background_color parameter requires input in a specific color string format (e.g., "#RRGGBB" or color names).

The Load & Resize Image node is from the ComfyUI-KJNodes node package.

Comments

Sign in with GitHub to join the discussion.

Loading comments…