Nodes/ComfyPanel/ImageMask_Scale
ComfyUI Node

ImageMask_Scale

Resize image and mask together, with rules, not just pixels

By Ginolazy·Created 6 months ago·Updated 2 days ago· 23
ImageMask_Scale
  • image
  • mask
  • scaled_image
  • scaled_mask
  • scale_data
target_size512
scale_mode
reference_side

ImageMask_Scale is the "resize under rules" node: it scales an image and its mask together to a target size, but with a couple of dials that plain resize nodes don't give you. You set a target_size, pick whether it applies to the long or short side of the image, and decide whether scaling is allowed to go up, down, or both. It's the node you reach for when "resize to 512" isn't specific enough.

The two knobs are what make it worth using over the core ImageScale. reference_side decides what target_size means: "long side" scales the image so its longer edge hits the target (a 1024×512 image becomes 512×256 at target 512), while "short side" anchors the shorter edge instead (1024×512 becomes 2048×1024 at target 512 - bigger, not smaller). scale_mode restricts direction: "scale up" only upscales and leaves already-large images alone, "scale down" only downscales, and "rescale" always forces the image to the target. Put together, that's the difference between "always make my short side 768 for the detail pass," "only upscale if it's smaller than 512," and "just make it 512."

Image and mask are both optional inputs, which is more useful than it looks: wire in just a mask and you get a resized mask plus a scale_data packet you can use to put things back. The third output, scale_data, records the original and scaled dimensions - and it's the whole point of this node's design, because it's what ImageMask_ScaleRestore (same pack) consumes to un-scale afterward. Resize, run your processing at the smaller size, then restore the original dimensions without ever having to remember what the original was. That's the pattern this node is built around, and it's the same detect-crop-refine discipline the ecosystem uses for detail passes - process small, restore big.

The resize itself is done with comfy.utils.common_upscale (lanczos when upscaling, area when downscaling) for images and nearest-neighbor for masks, so mask edges stay hard while image quality stays high. All three scale modes, both reference sides, and the target size (1–4096, default 512) are on the node.

Where it fits: pre-sampling resolution management, feeding a detailer or an upscaler that wants a specific size, or the scale-then-restore round trip above. It's a well-behaved utility - no surprises, no state to go stale, just consistent sizing.

Installing it

cd ComfyUI/custom_nodes
git clone https://github.com/Ginolazy/ComfyPanel
# restart ComfyUI

or ComfyUI Manager → "ComfyPanel". No models; standard pack deps. Quick mental check when it does the "wrong" thing: with reference_side on "long side" and scale_mode on "scale up", a 2048×1024 image at target 512 will not shrink - "scale up" means it only grows, so it passes through untouched. If you expect a forced downsize, that's "rescale" or "scale down". The two enums interacting is the one place beginners misread this node.

CategoryComfyPanel/Process & Restore

Inputs (5)

NameTypeDefaultDescription
target_sizeINT5121–4096
scale_modeCOMBO3 options: scale up, scale down, rescale
reference_sideCOMBO2 options: long side, short side
imageoptIMAGE
maskoptMASK

Outputs (3)

NameTypeDescription
scaled_imageIMAGE
scaled_maskMASK
scale_dataSCALE_DATA