Resize Image If Present
The optional-first-frame node that doesn't fake it
- image
- mask
- image
- mask
- width
- height
Some ComfyUI nodes solve hard math problems. This one solves a category of silent bug: "I want to optionally feed a first frame or reference image, but if nothing is connected, the graph should just... not."
Here's the trap it kills. In video workflows - Wan, Bernini, H3 - you often have a graph that can run with or without a reference image: a first-frame conditioning socket, a reference-video input, an optional keyframe. The lazy way to make an optional socket is to pipe a black placeholder frame when nothing's connected. That looks fine and is subtly wrong, because now the model is genuinely attending to a black frame instead of attending to nothing. Every edit and generation downstream inherits that artifact.
Resize Image If Present is the pack's answer, and the key sentence is in the node's own description: an unconnected image produces an absent image instead of a placeholder frame. No image in, no image out - and the downstream optional input correctly reads "nothing is here." One graph safely serves both the "with reference" and "without reference" cases without you maintaining two copies.
How it works
When an image is connected, it resizes - and optionally crops or pads - to your target dimensions, and applies the identical geometry to a matching mask so the two stay aligned. When nothing is connected, it returns nothing. That's the whole trick, and it's exactly the right amount of clever.
The inputs that matter
- image (optional) - leave unconnected to produce no image. This is the whole point.
- mask (optional) - transformed with the same geometry as the image.
- width / height - target size.
0derives the dimension from the other one; both0passes the input through untouched. That passthrough mode is handy when you want a node that only crops/pads. - resize_mode -
stretch,fit,crop(default),pad, orpad_edge.cropkeeps the full content and crops the overflow;padadds thepad_colorborder. - upscale_method -
nearest-exact,bilinear,area,bicubic, orlanczos(default). Lanczos is the safe pick for frames. - crop_position -
center,top,bottom,left,right. Both crop anchor and pad alignment. - divisible_by - rounds the output to a multiple, useful for models that want latents on a grid.
- pad_color - CSS color name, hex, or "0-255 / 0-1" RGB.
Outputs: image, mask, plus width and height of the result.
How to install
Ships with ComfyUI Turing Utils ("comfyui-svdint4" in Manager):
cd ComfyUI/custom_nodes
git clone https://github.com/wjie98/comfyui-svdint4
cd comfyui-svdint4
python -m pip install -v --no-build-isolation -e ./kernel
Pure image logic - no kernel needed for this node, but the pack installs as a unit, so build it once and restart.
The honest take
This is a plumbing node in the best sense: small, boring, and it prevents a whole class of "why does my video have a black flash at the start" threads. The crop default with lanczos is right for most reference-image jobs. Where people trip up is feeding a single frame into a node that's downstream of a video and expecting it to match the video's frame count - this resizes the image, not your thinking. Pair it with the pack's padding nodes and you've got the optional-reference story handled end to end.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| width | INT | 00–16384 | Target width. 0 derives it from height; width=height=0 passes the input through. |
| height | INT | 00–16384 | Target height. 0 derives it from width; width=height=0 passes the input through. |
| resize_mode | COMBO | crop | 5 options: stretch, fit, crop, pad, pad_edge |
| upscale_method | COMBO | lanczos | 5 options: nearest-exact, bilinear, area, bicubic, lanczos |
| crop_position | COMBO | center | Crop anchor or padded-content alignment. |
| divisible_by | INT | 11–512 | — |
| pad_color | STRING | 0, 0, 0 | RGB values in 0-255 or 0-1 form, a hex color, or a CSS color name. |
| imageopt | IMAGE | Leave unconnected to produce no image. | |
| maskopt | MASK | Optional mask transformed with the same geometry as the image. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| width | INT | — |
| height | INT | — |