Nodes/ComfyPanel/ScaleAny
ComfyUI Node

ScaleAny

A resizer that only scales when it actually should

By Ginolazy·Created 6 months ago·Updated 2 days ago· 23
ScaleAny
  • input
  • *
target_size512
scale_modescale up
reference_sidelong side

ComfyUI's stock ImageScale resizes whatever you give it, no questions asked. ScaleAny is the version that asks the question first: should I even touch this? It scales an image or a mask to a target size, but only when the resize is actually called for - and it picks the right interpolation per job instead of blurring your masks like they were photographs.

That conditional behavior is the reason you'd reach for it over the core node. You can wire it between a Load Image and a sampler and never think about it again: small inputs get pulled up to your working resolution, already-large ones pass through untouched, and masks stay crisp.

How it works

ScaleAny takes one * input - it auto-detects whether you've fed it a 4D image or a 3D mask from the tensor shape - and decides whether to scale based on your three settings:

  • target_size (INT, 1–4096, default 512): the pixel value you're aiming at.
  • scale_mode: scale up only upscales smaller images, scale down only downscales larger ones, rescale always resizes. This is the "ask the question" part.
  • reference_side: long side or short side - which edge target_size refers to. Long side is what most people want (fit within a 512 box); short side is for when you're matching a specific narrow dimension.

For images it uses lanczos when growing and area averaging when shrinking - area is the right call for downscaling, it resists the moiré aliasing you get with naive interpolation. Masks get nearest-neighbor, which is the important detail: nearest keeps mask edges hard and doesn't smear the boundary, so your inpainting region stays exact.

The output is the same type as the input. If nothing needs scaling, it returns the input untouched - no resampling, no quality loss.

Where it fits

It's a natural pre-sampler step: normalize everything to one resolution before batching. Pair it with MakeBatch (same pack) and you can stack inputs at wildly different sizes into a single uniform batch. And in a mask pipeline, ScaleAny is how you keep a painted mask at the exact size of your latent - which is the step that quietly breaks a lot of inpainting workflows when people forget it.

The honest caveats

scale up with lanczos from something tiny will get you something, but it's a resample, not a restoration. If you're going from 256 to 2048, you want a real upscaler - a 4x model or a tile-based pass - before this node, and let ScaleAny handle the final fit. Also note the cap: target_size maxes at 4096, so it can't be your only tool for monster canvas sizes. Both of those are "use the right tool per stage," not node defects.

Installing it

It ships in ComfyPanel:

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

Restart ComfyUI, or search ComfyPanel in ComfyUI Manager. The pack pulls in kornia, scipy, and opencv-python alongside the standard torch/numpy/Pillow - Manager will prompt for anything your install is missing. No model downloads. The Photoshop plugin is optional; this node is standalone.

CategoryComfyPanel/Image or Mask

Inputs (4)

NameTypeDefaultDescription
input*
target_sizeINT5121–4096
scale_modeCOMBOscale up3 options: scale up, scale down, rescale
reference_sideCOMBOlong side2 options: long side, short side

Outputs (1)

NameTypeDescription
**