A ComfyUI node that analyzes images and suggests optimal dimensions while preserving aspect ratio. This node is particularly useful in image-to-image and image-to-video workflows where maintaining aspect ratios and resolution constraints is crucial.

- Analyzes input images and suggests optimal dimensions.
- Preserves aspect ratio while fitting within minimum and maximum resolution constraints.
- Ensures dimensions are multiples of a specified number (e.g., 8 for SDXL).
- Handles both landscape and portrait orientations.
- Optional priority setting to choose between strictly enforcing maximum resolution or ensuring minimum resolution is always met.
- Passes through the original image unmodified for chaining with other nodes.
- Provides both constrained dimensions and aspect ratio information.
- Image: The input image to analyze (required).
- Constraint Mode: Choose how to handle conflicting constraints for extreme aspect ratios.
- Prioritize Min Resolution (Default): Ensures that neither dimension will be smaller than
min_res
. This is the recommended mode for most workflows, as it prevents generating images that are too small. In cases of extreme aspect ratios, this may cause the longer dimension to exceedmax_res
. - Prioritize Max Resolution (Strict): Strictly enforces the
max_res
limit on both dimensions. This guarantees the output will fit within amax_res
xmax_res
bounding box, which is useful for strict VRAM limits. In cases of extreme aspect ratios, this may cause the shorter dimension to fall belowmin_res
.
- Prioritize Min Resolution (Default): Ensures that neither dimension will be smaller than
- Min Resolution: Minimum resolution in pixels for either width or height.
- Max Resolution: Maximum resolution in pixels for either width or height.
- Multiple Of: Ensure dimensions are multiples of this number (e.g., 8 for SD-XL).
- Image: The unchanged input image (passed through).
- Constrained Width: Suggested width that fits the constraints.
- Constrained Height: Suggested height that fits the constraints.
- Constrained Aspect Ratio: The aspect ratio of the constrained dimensions.
- Original Aspect Ratio: The original aspect ratio of the input image.
- Connect your image source to the
Image
input. - Select your desired
Constraint Mode
. For most uses, the default is ideal. - Set your desired
Min Resolution
andMax Resolution
constraints. - Set the
Multiple Of
value based on your model requirements (e.g., 8 for SDXL). - Connect the
Image
output to your preferred resize node (e.g., Image Resize). - Use the
Constrained Width
andConstrained Height
outputs to set the dimensions in your resize node.
- Image-to-Image: Ensure consistent image sizes while maintaining aspect ratios.
- Image-to-Video: Prepare frames with proper dimensions for video generation.
- Batch Processing: Standardize image dimensions across multiple images.
- Resolution Optimization: Find optimal dimensions for specific model requirements.
- VRAM Management: Use "Prioritize Max Resolution" mode to avoid exceeding VRAM limits with unusually large images.
Use ComfyUI Manager or follow these manual installation steps:
- Navigate to your
ComfyUI/custom_nodes/
directory. - Clone this repository:
git clone https://github.com/EnragedAntelope/ComfyUI-ConstrainResolution.git
- Restart ComfyUI.
See the LICENSE file for details.