Nodes/Comfy_Felsirnodes/RescaleMaintainAspect
ComfyUI Node

RescaleMaintainAspect

Letterbox, don't distort — the controlnet map's best friend

By Felsir·Created 3 years ago·Updated about a year ago· 23
RescaleMaintainAspect
  • image_in
  • IMAGE
width512
height512
halign
valign
fillcolor

Rescale Maintain Aspect is the pack's no-drama utility: it fits an image into a target width and height without changing its aspect ratio, and fills the leftover space with black, white, or transparency. No cropping, no distortion, no focal points to choose - just a letterboxed (or pillarboxed) image at exactly the size you asked for.

It sounds boring until you hit the problem it solves: controlnet and depth-map prep. A depth map or line-art pass has to match the canvas you're generating on. Feed the model a 1344x768 latent and a 1024x1024 controlnet image, and the conditioning geometry drifts out of alignment with what you're sampling. The naive fix - resizing to fill the target - stretches the subject and breaks its proportions, which defeats the whole point of a structural pass. This node fits the image inside instead, and pads the rest.

The README's example is exactly that: a stick-figure depth map rescaled to the generation canvas, aligned to the bottom, black fill above it. And in the author's original launch thread on r/comfyui, a commenter called this node "overkill" - which, in this community, is the highest praise a utility can get.

How it works

It computes the target aspect ratio from your width / height, fits the source inside so either its width or its height hits the edge first (whichever is tighter), resizes to that, and pastes the result onto a canvas of the exact target size at the alignment you choose. Plain PIL math, no models involved.

The inputs that matter

  • width / height - the target canvas, 16–2048.
  • halign / valign - center / left / right and center / top / bottom. These matter more than they look: for a depth map that should sit at the bottom of a 16:9 frame, that's bottom + black - and you usually want the subject where the target composition expects it, or the conditioning fights the prompt.
  • fillcolor - black / white / transparent, for the padding.

Output: the resized IMAGE, and nothing else - a single output, no crop rect to babysit. It's also the one node in this pack whose batch loop actually behaves, so you can run a folder of depth maps through it without drama.

One warning

fillcolor=transparent produces an RGBA image, and most ComfyUI nodes expect plain 3-channel RGB - feed a 4-channel tensor into a node that isn't ready for it and you'll get a confusing error. Use transparent only if the next node actually handles alpha (or you're exporting to PNG). For controlnet work, black is usually right anyway.

Installing it

The pack has zero extra dependencies - pure PIL/numpy/torch, already in ComfyUI. ComfyUI Manager: search for Comfy_Felsirnodes (or "Felsir"), install, restart. Manual: cd ComfyUI/custom_nodes and git clone https://github.com/Felsir/Comfy_Felsirnodes, restart. The node is under Add Node → Felsir.

CategoryFelsir

Inputs (6)

NameTypeDefaultDescription
image_inIMAGE
widthINT51216–2048
heightINT51216–2048
halignCOMBO3 options: center, left, right
valignCOMBO3 options: center, top, bottom
fillcolorCOMBO3 options: black, white, transparent

Outputs (1)

NameTypeDescription
IMAGEIMAGE