ComfyUI > Nodes > ComfyUI-tbox > Image Constrain

ComfyUI Node: Image Constrain

Class Name

ConstrainImageNode

Category
tbox/Image
Author
ai-shizuka (Account age: 3606days)
Extension
ComfyUI-tbox
Latest Updated
2025-04-22
Github Stars
0.02K

How to Install ComfyUI-tbox

Install this extension via the ComfyUI Manager by searching for ComfyUI-tbox
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter ComfyUI-tbox in the search bar
After installation, click the Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • 16GB VRAM to 80GB VRAM GPU machines
  • 400+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 200+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

Image Constrain Description

Adjusts image size to fit specified dimensions while maintaining aspect ratio and quality.

Image Constrain:

The ConstrainImageNode is designed to adjust the size of an image while maintaining its aspect ratio, ensuring that it fits within specified maximum and minimum dimensions. This node is particularly useful for preparing images for various applications where size constraints are critical, such as web design, digital art, or any scenario where images need to be uniformly resized without distortion. By automatically adjusting the image dimensions, it helps maintain visual consistency and quality, preventing images from being stretched or compressed inappropriately. The node also offers an option to crop images if necessary, providing flexibility in how images are resized to meet the specified constraints.

Image Constrain Input Parameters:

images

This parameter accepts the image or images that you want to resize. It is the primary input and serves as the source material for the resizing operation. The images should be in a compatible format that the node can process.

max_width

This integer parameter sets the maximum allowable width for the resized image. The default value is 1024, with a minimum value of 0. It ensures that the image does not exceed this width, helping to maintain a consistent size across different images.

max_height

Similar to max_width, this integer parameter defines the maximum height for the resized image. It also defaults to 1024 and has a minimum value of 0. This parameter ensures that the image height does not surpass the specified limit, maintaining uniformity in image dimensions.

min_width

This integer parameter specifies the minimum width that the resized image should have. The default value is 0, with a minimum value of 0. It ensures that the image is not resized to a width smaller than this value, which can be important for maintaining image visibility and detail.

min_height

This parameter sets the minimum height for the resized image, with a default value of 0 and a minimum value of 0. It ensures that the image height does not fall below this threshold, preserving the image's integrity and detail.

crop_if_required

This parameter is a choice between "yes" and "no," with the default being "no." It determines whether the image should be cropped to fit within the specified dimensions if resizing alone cannot achieve the desired size. This option provides additional control over how images are adjusted to meet size constraints.

Image Constrain Output Parameters:

IMAGE

The output is the resized image or images, adjusted to fit within the specified maximum and minimum dimensions while maintaining the original aspect ratio. This output ensures that the images are ready for use in applications that require specific size constraints, preserving both quality and consistency.

Image Constrain Usage Tips:

  • To maintain the original aspect ratio while resizing, ensure that both max_width and max_height are set to values that reflect the desired maximum dimensions for your images.
  • Use the crop_if_required option set to "yes" if you need to ensure that images fit exactly within the specified dimensions, even if it means cropping some parts of the image.
  • Set appropriate min_width and min_height values to prevent images from being resized too small, which can lead to loss of detail and visibility.

Image Constrain Common Errors and Solutions:

Image size exceeds maximum dimensions

  • Explanation: This error occurs when the image cannot be resized to fit within the specified maximum dimensions without cropping.
  • Solution: Consider enabling the crop_if_required option to allow the node to crop the image to fit within the maximum dimensions.

Image size below minimum dimensions

  • Explanation: This error happens when the resized image is smaller than the specified minimum dimensions.
  • Solution: Adjust the min_width and min_height parameters to ensure they are set to appropriate values that the image can realistically meet after resizing.

Image Constrain Related Nodes

Go back to the extension to check out more related nodes.
ComfyUI-tbox
RunComfy
Copyright 2025 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals. RunComfy also provides AI Models, enabling artists to harness the latest AI tools to create incredible art.

Image Constrain