Nodes/ComfyUI-Beyond_nodes/Scale an Image/Mask as a Ref 🦾
ComfyUI Node

Scale an Image/Mask as a Ref 🦾

Make your mask match your reference image's dimensions

By beyondprompting·Created 9 months ago·Updated 7 months ago· 0
Scale an Image/Mask as a Ref 🦾
  • scale_as
  • image
  • mask
  • image
  • mask
  • original_size
  • widht
  • height
fit
method

Scale an Image/Mask as a Ref answers a question that comes up constantly in masking workflows: "how do I get my mask to be exactly the same size as this reference image?" Instead of you typing target dimensions by hand, you hand the node a reference - the scale_as input - and it resizes your image and/or mask to match, with a choice of how to fit.

This is one of those glue nodes that quietly saves you from the most common mask failure there is: a mask that's 512×512 sitting on a 768×512 image. When the mask and the image disagree in shape, every downstream conditional either errors or silently does the wrong thing. This node is the fix.

How it works

scale_as can be an image (or a batch - it takes the first frame) and its width/height become the target size. Your image and mask are each resized to that target using one of three fit strategies and one of six resampling methods. What you get back is everything aligned to the reference's dimensions.

The fit choice is where the craft is:

  • letterbox - shrink to fit inside, adding black bars on the short side. Nothing is cropped, but you get empty padding.
  • crop - scale to cover, then crop the overflow. No padding, but edges get cut.
  • fill - stretch to the exact target, distorting aspect ratio. Never crops, but can squish.

The method list is the standard resampling ladder (lanczos, bicubic, hamming, bilinear, box, nearest) - lanczos is the default and right for almost everything.

The inputs that matter

  • scale_as (required, any type) - the reference whose dimensions define the target.
  • fit (required) - letterbox, crop, or fill.
  • method (required) - resampling quality.
  • image (optional) - the image to resize. Leave empty if you only care about the mask.
  • mask (optional) - the mask to resize. Leave empty if you only care about the image.

Outputs: image, mask, plus original_size (a BOX with the pre-resize width/height) and the target widht and height as ints.

Two quirks to know: the output name is widht - yes, misspelled in the actual source, not a typo on this page - and when you feed neither image nor mask, the node returns empty outputs with a target of 0×0. It needs at least one input to do anything.

Install

Part of ComfyUI-Beyond_nodes. ComfyUI Manager → search "Beyond_nodes" → install → restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/beyondprompting/ComfyUI-Beyond_nodes

Restart. No extra dependencies.

Common issues

  • The mask comes back black or empty. Check that you actually connected mask, and that scale_as is a real image - with no reference the node has nothing to scale to.
  • I wanted no cropping and no bars. That's fill, accepting the distortion. If distortion matters more than coverage, that's the price.
  • The output name says widht. Blame the source code, not your eyes. The value is the target width.

It's a small utility, but in mask-based editing it's the difference between "why won't this connect" and a mask that lines up pixel-for-pixel with your reference on the first try.

CategoryBeyond nodes/Masking

Inputs (5)

NameTypeDefaultDescription
scale_as*
fitCOMBO3 options: letterbox, crop, fill
methodCOMBO6 options: lanczos, bicubic, hamming, bilinear, box, nearest
imageoptIMAGE
maskoptMASK

Outputs (5)

NameTypeDescription
imageIMAGE
maskMASK
original_sizeBOX
widhtINT
heightINT