Nodes/ComfyUI_Swwan/Image Resize Range (Swwan)
ComfyUI Node

Image Resize Range (Swwan)

Resize only when the picture is too small or too big

By aining2022·Created 10 months ago·Updated about 18 hours ago· 33
Image Resize Range (Swwan)
  • 图像
  • 遮罩
  • 图像
  • 遮罩
◄限制模式长边►
◄最小尺寸1024►
◄最大尺寸3000►
◄整除数0►

What it's for

Most resize nodes ask "what size do you want?" This one asks "what sizes are acceptable?" You give it a floor and a ceiling, and it only touches the image if the chosen side falls outside that window. Anything already inside the range passes through at its original resolution - no resample, no softening.

That's the node you want when your inputs come from somewhere you don't control: a folder of scraped images, a batch from a crop node, user uploads. You want everything at least 1024 on the long side and nothing above 3000, without upscaling the good ones just to make a uniform number.

It's one of the pack's 21 primary entries, transplanted from Goohaitools rather than KJNodes or LayerStyle. Which explains the widgets: 限制模式, 最小尺寸, 最大尺寸, 整除数 are the original Chinese labels, displayed as-is. Search for Swwan and you'll find it; don't hunt for an English translation.

How the window works

限制模式 picks which measurement the range applies to: 长边 (longest side, the default), 短边 (shortest side), 宽度 (width), 高度 (height), or 宽度与高度 (both - each axis gets clamped independently, so this one can change your aspect ratio).

The default pair is 1024 as the minimum and 3000 as the maximum. Underneath, the image is converted to an 8-bit PIL image, LANCZOS-resampled, and converted back; masks take a separate BILINEAR path, which is a little softer and quantised to 256 levels - fine for inpaint masks, noticeable if you were counting on a smooth feathered gradient surviving.

整除数 is the interesting knob and it defaults to 0, meaning "don't round." For latent-based models that's the wrong default for you: set it to 8, 16 or 64 and the node scales to fit and then centre-crops to an exact multiple of that number. Note it crops rather than pads, so your framing shifts by a few pixels.

Inputs and outputs

Both inputs are optional: 图像 (IMAGE) and 遮罩 (MASK). At least one has to be connected or it raises 至少需要输入图像或遮罩中的一个. If both are there, their batch sizes must match - a mismatch is a hard ValueError, not a silent broadcast. Mask-only use is supported and it's genuinely useful: clamp a 4096-wide inpaint mask down to your 3000 ceiling and the mask lands in exactly the geometry the image would have.

One behaviour worth knowing: an all-black mask batch is detected and regenerated at the new size rather than resampled, so an empty mask stays empty instead of picking up noise.

Outputs are just 图像 and 遮罩 at 限制模式-approved dimensions. Nothing exotic to wire - the mask output goes straight into the inpaint or composite node you were already using.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/aining2022/ComfyUI_Swwan
cd ComfyUI_Swwan
python -m pip install -r requirements.txt

Restart, refresh the browser, search Swwan. The dependencies this node actually touches - Pillow and numpy - arrive with the pack's requirements, and nothing here needs a model file or a GPU. Windows portable users install with .\python_embeded\python.exe -m pip install -r .\ComfyUI\custom_nodes\ComfyUI_Swwan\requirements.txt.

Common issues

Nothing resizes. Check 最小尺寸 and 最大尺寸 first - if your image already sits inside the window, doing nothing is the correct answer, not a bug.

Everything comes out 8 pixels short on one side. That's 整除数 doing its centre-crop. Set it to 0 to keep the exact aspect ratio.

ComfyUI Manager flags a conflict. This pack is a reimplementation of a lot of other packs' nodes, so Manager's overlap warnings with KJNodes, LayerStyle or Impact are normal and mostly cosmetic - but they're also why this pack has a noisy reputation. If a node that used to work went missing after installing it, that's usually a frontend clash, and the fix in the field has been to disable or remove the pack rather than debug it:

ls ComfyUI/custom_nodes | grep -i swwan

It fails on batch sizes. The image and mask batches have to be the same length. Slice them with a batch tool before the resize, not after.

CategorySwwan/Image

Inputs (6)

NameTypeDefaultDescription
图像optIMAGE—
遮罩optMASK—
限制模式optCOMBO长边5 options: 长边, 短边, 宽度, 高度, 宽度与高度
最小尺寸optINT102410–10240—
最大尺寸optINT300010–10240—
整除数optINT00–512—

Outputs (2)

NameTypeDescription
图像IMAGE—
遮罩MASK—