图像缩放丨尺寸
Resize the image and its mask together — or they drift apart
- image
- mask
- image
- mask
- width
- height
Here's a bug that's cost everyone a session at some point: you upscale your image, forget that the mask was made at the old resolution, and suddenly your inpaint region is misaligned by 200 pixels. ImageScaling exists to kill that whole class of bug - it resizes the image and its mask in the same operation, so they can never drift apart. That single feature is why this is my default resize node for any masked pipeline.
It's from ComfyUI-QING (display name "图像缩放丨尺寸"), the Chinese-authored utility pack. Display names are bilingual; the dropdowns you'll see are in Chinese with English interpolation labels mixed in.
How it works
The node takes an optional image, an optional mask, or both, and resizes them together. You describe the target size through three cooperating controls:
scale_definition- whatdefinition_valuemeans: 无 (none), 最长边 (longest side), 最短边 (shortest side), 宽度 (width), 高度 (height), 百分比 (percentage), or 总像素 (total pixels). Default is longest side.definition_value- the number that goes with the definition. Longest side 1024 = "keep aspect ratio, longest edge 1024."multiple_of- rounds the result up to a multiple of this number. Default 2; set it to 8 or 16 to keep dimensions sampler-friendly. This is the "make sure it's divisible by X" control you'd otherwise eyeball.
On top of that there's scale_mode: 保持比例 (keep ratio), 拉伸 (stretch - distorts to exact W×H), 裁剪 (crop - scales to cover, then crops), 填充 (pad - scales to fit, then pads). And optional width/height INT inputs for when you want to pin exact dimensions.
Interpolation options mirror the pack's flip node: Lanczos (default), 最近邻 (nearest), 双线性 (bilinear), 双三次 (bicubic), 区域 (area), 精确最近邻 (nearest-exact). Lanczos for downscaling, nearest if you're resizing masks and want hard edges.
Outputs: image, mask, and width/height INTs - so the actual resulting size is available to the graph, not just to your eyes.
Why you'll reach for it
Two scenarios. First, any time an image and a mask must stay in lockstep - resize for a tiled upscale, resize for a detail pass, resize for a video frame sequence - this is the node that makes misalignment impossible. Second, prepping latents: set scale_definition to longest side 1024 and multiple_of to 64 (or 8, depending on your model's latent layout) and you get clean sampler-friendly dimensions every run, no mental arithmetic.
The honest caveat: for pure single-image upscaling, ComfyUI core's ImageScale is fine and this adds nothing you need. This node earns its place when a mask is riding along - that's the differentiator.
Installing
Part of ComfyUI-QING, install once, all 79 nodes appear. ComfyUI Manager: search "ComfyUI-QING". Or:
cd ComfyUI/custom_nodes
git clone https://github.com/GAO-SHIQING/ComfyUI-QING
cd ComfyUI-QING
python install_dependencies.py # or: pip install -r requirements.txt
Restart ComfyUI. Pure pip deps (Pillow, opencv-python, scipy, scikit-image, cairosvg), no model downloads. China mirror: --mirror --auto. Python ≥ 3.9, current ComfyUI.
Gotchas
If you feed neither image nor mask it raises an error demanding at least one - feed it something. 拉伸 (stretch) will happily distort your aspect ratio, which is a feature until you forget you selected it and wonder why everything looks squashed. And multiple_of only rounds up, so "multiple of 64, target 1024" gives you 1024, but "multiple of 64, target 1030" jumps to 1088 - if your output dims are mysteriously larger than requested, that's the control to check. The mask resizes with nearest-style edges by default, which is what you want for a mask; don't be alarmed that the mask looks "harder" than the image.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| scale_mode | COMBO | 保持比例 | 4 options: 保持比例, 拉伸, 裁剪, 填充 |
| interpolation | COMBO | Lanczos | 6 options: Lanczos, 最近邻, 双线性, 双三次, 区域, 精确最近邻 |
| scale_definition | COMBO | 最长边 | 7 options: 无, 最长边, 最短边, 宽度, 高度, 百分比, +1 |
| definition_value | INT | 10241–999999999 | — |
| multiple_of | INT | 21–256 | — |
| imageopt | IMAGE | — | |
| maskopt | MASK | — | |
| widthopt | INT | 00–999999999 | — |
| heightopt | INT | 00–999999999 | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| width | INT | — |
| height | INT | — |