Image Constrain
Keep a batch of images inside a size box
- images
- IMAGE
Shown in the node browser as Image Constrain, this one's for the boring-but-necessary job of keeping images inside a size boundary before they hit something downstream that cares - a save step with a file-size budget, an upload target with a resolution cap, or just normalizing a batch of differently-sized source images before you do anything else with them.
How it works
You give it four bounds - a max and a min for both width and height - and it scales (and optionally crops) each image in the batch to land inside that box. If an image is already smaller than your max, nothing forces it bigger unless you've also set a min above zero; the default min is 0, so out of the box this node only ever shrinks oversized images and leaves everything else alone. If getting an image to satisfy both a max and a min on the same axis would mean changing its aspect ratio, crop_if_required is what decides whether the node crops it to fit exactly (yes) or just resizes and accepts that it may not land perfectly on the minimum bound (no, the default).
The inputs and outputs that matter
images(required IMAGE) - your batch.max_width/max_height(default 1024 each) - the ceiling. Nothing bigger than this gets through unscaled.min_width/min_height(default 0 each) - the floor. Leave these at 0 unless you specifically need small images forced bigger; a nonzero min will upscale anything that comes in smaller than it.crop_if_required(yes/no, defaultno) - whether the node crops to hit an exact target shape or just resizes and lets the aspect ratio be whatever it ends up being.
Output: IMAGE - and it's worth noting this one comes back as a list, not a single batched tensor. That's a real wiring quirk: if you feed this node's output into something expecting a standard image batch and get a type-mismatch error, this is why - you may need a list-to-batch step in between.
How to install it
Via ComfyUI Manager: search ComfyUI-tbox, install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/ai-shizuka/ComfyUI-tbox
then restart. No models or extra dependencies for this one - it's plain image resizing logic, nothing to download. The pack's README doesn't cover it (or much else - it's three empty section headers), but there's nothing here that needed documenting beyond the parameter names themselves.
Common issues & troubleshooting
Images come out smaller than you expected, even without touching min_width/min_height. That's expected behavior - the node's whole job is enforcing the max_* ceiling, and with min_* at the default of 0 there's no floor pulling anything back up.
Output isn't a clean square, or doesn't match your target aspect ratio exactly. Set crop_if_required to yes - left at no, the node prioritizes not cropping your content over hitting an exact shape.
A downstream node throws a type error when fed from this one. Check whether it expects a batched image tensor rather than a list - this node's output is_list, which not every consumer expects. Insert a batching step if you hit this.
Unsure whether it's scaling or cropping in a given run. With min_width/min_height left at 0, it's scaling only - cropping only kicks in through crop_if_required, and only when a min/max conflict on the same axis forces the question.
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 | — |