Constrain Resolution
Never feed a model the wrong dimensions again
- image
- resized_image
- original_image
- width
- height
- final_aspect_ratio
- original_aspect_ratio
Constrain Resolution is the node you grab when a workflow refuses to run because your input is 1800×1013 and the model wants 1280×720 with everything divisible by 16. It resizes any image to a min/max resolution box, rounds the output so both dimensions land on a multiple of 2, 8, 16, 32, or 64, and crops a few pixels to keep the aspect ratio intact. One node instead of the usual three-node chain of resize → round → crop, and it guarantees every output actually hits the numbers it reports.
Why you'll end up reaching for it
Diffusion models are weirdly picky about canvas size. SD 1.5 wants ~512, SDXL has a set of trained aspect ratios, and Flux must be divisible by 64. Image-to-video is worse - Wan and LTX want exact sizes and dimensions divisible by 8 or 16, and running a 720p clip at 1280×720 versus 1345×723 is the difference between a clean generation and a blocky or OOM'd one. Then there's the VRAM angle: if you're on 8GB trying to feed Wan frames, you need a hard cap on resolution, not a suggestion.
This node handles all three rules (min size, max size, divisibility) in one step and doesn't let any of them silently break. If you're prepping frames for i2v or running the same image through several models, it's the boring utility that stops being the thing you debug at 2am.
How it works
The math is straightforward: it scales the longest side to max_res, bumps the result up if either dimension would fall below min_res, rounds both to the nearest multiple_of, then - when rounding skews the aspect ratio - resizes so one dimension is slightly too big and crops the excess. The actual resizing uses ComfyUI's own common_upscale, so results match the core resize nodes, and bicubic/lanczos output is clamped to the valid range so you don't get overshoot halos. It's built on the ComfyUI v3 node API, so no compatibility shims needed.
The inputs that matter
You'll set min_res and max_res (defaults 704/1280) and multiple_of (default 2; go 8/16/32/64 for i2v). Then two decisions:
constraint_mode- what wins when an extreme aspect ratio makes both limits impossible. "Prioritize Min Resolution" (default) guarantees neither dimension dips belowmin_res, even if the long side exceedsmax_res. "Prioritize Max Resolution (Strict)" enforces a hard VRAM-safe ceiling, even if the short side falls under. For a strict cap, use strict.crop_as_required- on by default, and it's the reason your output is exactly the target size. Flip it off withmultiple_of=1and you get a no-crop, keep-every-pixel resize instead.
crop_position (center/top/bottom/left/right) picks what survives the crop - top keeps faces in headshots. resize_method defaults to lanczos; nearest-exact is there for pixel art and masks, area for big downscales.
Outputs
The main output is resized_image. There's also original_image (a passthrough, handy when you want the untouched frame alongside), width/height as ints for downstream nodes, and final_aspect_ratio/original_aspect_ratio floats if you want to monitor how much the ratio drifted.
Installing it
Easiest via ComfyUI Manager - search "Constrain Resolution". Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/EnragedAntelope/ComfyUI-ConstrainResolution.git
Restart ComfyUI. That's the whole install: the requirements file is deliberately empty - no torch install, no model downloads, just ComfyUI's own environment. Python 3.10+.
When it bites you
Not many traps, but a few gotchas worth knowing:
- Extreme aspect ratios in min mode can surprise you. A 3:1 panorama scaled to meet
min_resblows the long side way pastmax_res. The node logs a warning if it has to upscale more than 4×; switch to Strict mode if you need the hard cap. - It will crop unless you say otherwise. If your output loses the edges you wanted, that's
crop_as_required=Truedoing its job - set it to false and accept slightly non-multiple dimensions. max_resbelowmin_resis rejected at validation, which saves you a confusing black image.
For i2v prep the README's recipe is the right starting point: min_res=768, max_res=1024, multiple_of=16, then tighten max_res to whatever your card survives. One clean node, no surprises.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Input image to analyze and resize | |
| min_res | INT | 7041–65536 | Minimum resolution in pixels for width and height. Neither output dimension will fall below this. |
| max_res | INT | 12801–65536 | Maximum resolution in pixels. Every image is rescaled so its longest side lands here, so images already in range are resized too. In 'Prioritize Min Resolution' mode the long side may exceed this on extreme aspect ratios. |
| multiple_of | INT | 21–256 | Ensures output dimensions are multiples of this number. Common values: 2 (most models), 8, 16, 32, or 64 (optimal performance). Set to 1 to disable rounding. |
| resize_method | COMBO | lanczos | Interpolation method used when resizing. • lanczos: Sharpest results, best overall quality (default) • bicubic: High quality, slightly softer than lanczos • bilinear: Fast, slightly soft • nearest-exact: No interpolation — for pixel art or masks • area: Good for large downscales |
| constraint_mode | COMBO | Prioritize Min Resolution | How to handle conflicts when extreme aspect ratios make it impossible to satisfy both min and max. • Prioritize Min Resolution: Ensures neither dimension falls below min_res (may exceed max_res) • Prioritize Max Resolution (Strict): Strictly enforces max_res limit (may go below min_res) |
| crop_as_required | BOOLEAN | true | Enable cropping to achieve exact target dimensions when rounding causes aspect ratio changes. Disable if preserving the entire image is more important than exact dimensions. |
| crop_position | COMBO | center | Where to crop from when 'Crop as Required' is enabled. • center: Crop equally from all sides • top: Keep top portion, crop from bottom • bottom: Keep bottom portion, crop from top • left: Keep left portion, crop from right • right: Keep right portion, crop from left |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| resized_image | IMAGE | Image resized to the constrained dimensions |
| original_image | IMAGE | Original image passed through unchanged for workflow flexibility |
| width | INT | Final width after constraints and rounding |
| height | INT | Final height after constraints and rounding |
| final_aspect_ratio | FLOAT | Aspect ratio of the output image (width/height) |
| original_aspect_ratio | FLOAT | Aspect ratio of the input image for comparison |