Nodes/ComfyUI-ConstrainResolution/Constrain Resolution
ComfyUI Node

Constrain Resolution

Never feed a model the wrong dimensions again

By EnragedAntelope·Created 2 years ago·Updated about 20 hours ago· 13
Constrain Resolution
  • image
  • resized_image
  • original_image
  • width
  • height
  • final_aspect_ratio
  • original_aspect_ratio
min_res704
max_res1280
multiple_of2
resize_methodlanczos
constraint_modePrioritize Min Resolution
crop_as_requiredtrue
crop_positioncenter

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 below min_res, even if the long side exceeds max_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 with multiple_of=1 and 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_res blows the long side way past max_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=True doing its job - set it to false and accept slightly non-multiple dimensions.
  • max_res below min_res is 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.

Categoryimage/resolution

Inputs (8)

NameTypeDefaultDescription
imageIMAGEInput image to analyze and resize
min_resINT7041–65536Minimum resolution in pixels for width and height. Neither output dimension will fall below this.
max_resINT12801–65536Maximum 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_ofINT21–256Ensures 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_methodCOMBOlanczosInterpolation 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_modeCOMBOPrioritize Min ResolutionHow 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_requiredBOOLEANtrueEnable 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_positionCOMBOcenterWhere 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)

NameTypeDescription
resized_imageIMAGEImage resized to the constrained dimensions
original_imageIMAGEOriginal image passed through unchanged for workflow flexibility
widthINTFinal width after constraints and rounding
heightINTFinal height after constraints and rounding
final_aspect_ratioFLOATAspect ratio of the output image (width/height)
original_aspect_ratioFLOATAspect ratio of the input image for comparison