Constrain Image for Video π
Prep a reference frame for image-to-video
- images
- IMAGE
This is the sibling of Constrain Image, same four bounds, same crop switch - but one schema difference gives away exactly why it's a separate node. Constrain Image returns a list of images, happy to constrain a whole batch where each one might land on a slightly different final size. This one returns a single IMAGE. That's not an oversight - it's the point. Video pipelines want one canonical frame size, not a batch of independently-sized images.
Part of ComfyUI-Custom-Scripts, pythongosssss's utility pack, and this particular node earns its keep in image-to-video (I2V) workflows specifically.
Why I2V needs this
I2V - animating forward from a reference image - is the mode most of the community reaches for over pure text-to-video, precisely because anchoring generation to a known first frame solves a lot of the consistency problems that plague T2V. But that only works cleanly if the reference image is actually a size the video model expects. Feed it something wildly off-spec and you either get an outright error or the model quietly mangles the frame to fit before it ever starts generating motion.
The inputs that matter
images takes your reference IMAGE. max_width/max_height (both default 1024) cap the size; min_width/min_height (both default 0) set a floor. crop_if_required (yes/no, default no) decides what happens when the bounds and the source's aspect ratio don't agree - off, it does its best with pure scaling; on, it crops to hit the target exactly.
For a single canonical reference frame, cropping to an exact target is usually the more predictable choice than letting one of your bounds go unmet through scale-only distortion - worth defaulting crop_if_required to yes here more often than you might for a general-purpose image resize.
The min bounds matter more here than in the plain image-batch case, too: a reference image that's too small gets scaled up to fit rather than passed through undersized, which keeps the video model from starting off a reference frame far below its own training resolution.
Picking actual numbers
Rather than guessing, match what the video community actually runs. Standard Wan outputs cluster around 480p (854Γ480) and 720p (1280Γ720), with some pushing higher-resolution runs up to 1536Γ864 on higher-VRAM cards. Setting max_width/max_height to one of those pairs - 1280Γ720 is a reasonable default - before your reference image hits the sampler beats leaving it at the node's generic 1024Γ1024 default and hoping for the best.
Installing it
- ComfyUI Manager - search "ComfyUI-Custom-Scripts", install, restart.
- Manual -
cd ComfyUI/custom_nodes && git clone https://github.com/pythongosssss/ComfyUI-Custom-Scripts, restart.
No models, no extra dependencies - pure image math, same as its sibling.
Common issues
Video model errors on the reference image entirely. This node gets you into the right ballpark; it doesn't guarantee an exact dimension or aspect ratio a particularly fussy sampler might demand. Check your specific video pipeline's documented requirements if the generic constrain-to-bounds output still isn't accepted.
Reference image looks stretched in the generated video. crop_if_required was off and your source aspect ratio didn't match the target bounds cleanly. Turn cropping on for a more predictable single-frame result.
Downstream node expects a single IMAGE but you're hitting a wiring error. That should be this node doing its job correctly - output here is a single IMAGE, not a list. If you're still seeing a mismatch, double-check you actually used this node and not the plain Constrain Image, whose output is list-typed and won't slot into a single-IMAGE input the same way.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | β | |
| max_width | INT | 1024 | β |
| max_height | INT | 1024 | β |
| min_width | INT | 0 | β |
| min_height | INT | 0 | β |
| crop_if_required | COMBO | no | 2 options: yes, no |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | β |