Nodes/comfyui-svdint4/Resize Image If Present
ComfyUI Node

Resize Image If Present

The optional-first-frame node that doesn't fake it

By wjie98·Created 2 months ago·Updated about 10 hours ago· 2
Resize Image If Present
  • image
  • mask
  • image
  • mask
  • width
  • height
width0
height0
resize_modecrop
upscale_methodlanczos
crop_positioncenter
divisible_by1
pad_color0, 0, 0

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. 0 derives the dimension from the other one; both 0 passes 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, or pad_edge. crop keeps the full content and crops the overflow; pad adds the pad_color border.
  • upscale_method - nearest-exact, bilinear, area, bicubic, or lanczos (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.

CategoryTuring Utils/image

Inputs (9)

NameTypeDefaultDescription
widthINT00–16384Target width. 0 derives it from height; width=height=0 passes the input through.
heightINT00–16384Target height. 0 derives it from width; width=height=0 passes the input through.
resize_modeCOMBOcrop5 options: stretch, fit, crop, pad, pad_edge
upscale_methodCOMBOlanczos5 options: nearest-exact, bilinear, area, bicubic, lanczos
crop_positionCOMBOcenterCrop anchor or padded-content alignment.
divisible_byINT11–512
pad_colorSTRING0, 0, 0RGB values in 0-255 or 0-1 form, a hex color, or a CSS color name.
imageoptIMAGELeave unconnected to produce no image.
maskoptMASKOptional mask transformed with the same geometry as the image.

Outputs (4)

NameTypeDescription
imageIMAGE
maskMASK
widthINT
heightINT