Nodes/ComfyUI Layer Style/LayerUtility: Image Mask Scale As V2
ComfyUI Node Runs on cloud

LayerUtility: Image Mask Scale As V2

Image Mask Scale As V2

By chflame163·Created 3 years ago·Updated 4 days ago· 3,113
LayerUtility: Image Mask Scale As V2
  • scale_as
  • image
  • mask
  • image
  • mask
  • original_size
  • widht
  • height
◄fit▾►
◄method▾►
â—„background_color#FFFFFFâ–º

This is the "resize to match that other thing" node, and it's one of those unglamorous utilities you end up using in nearly every multi-image workflow. Size mismatches break everything downstream - you can't blend, composite, or concat two images at different dimensions - and matching them by hand means copying numbers between nodes. ImageMaskScaleAsV2 takes a reference input and scales your image and/or mask to match it automatically. V2 is the current version, and the thing it adds over the original is a background_color control.

The heart of it is the scale_as input, typed * so it accepts anything with a size - an image, a mask, a latent. The node reads that reference's dimensions and scales your content to fit. Because it follows the reference rather than a hardcoded number, the workflow stays correct when you change resolution upstream; you never go back and edit a resize value.

Settings: fit controls how mismatched aspect ratios resolve - letterbox fits the whole image inside the target and pads the gap, crop fills the frame and trims overflow, fill stretches to exact dimensions (distorting if the ratios differ). background_color is the V2 addition: it's the color of the letterbox padding (default white, #FFFFFF), so if you're fitting into a target and want black bars or a color-matched fill instead of white, this is where you set it - a small thing that saves an extra fill node. method is the resampling filter, lanczos being the sharp default (bilinear/bicubic softer, nearest for hard pixel edges). Both image and mask inputs are optional, so you can scale one or both; running an image and its mask through together keeps them dimensionally locked, which is the usual reason you're here.

Outputs: image, mask, original_size (a BOX holding the pre-scale dimensions in case you want to undo the resize later), and widht and height - "widht" being the pack's own typo - giving the new size as integers for downstream use.

Install is the pack standard: in ComfyUI Manager search "ComfyUI Layer Style" and install, or cd ComfyUI/custom_nodes && git clone https://github.com/chflame163/ComfyUI_LayerStyle, then pip install -r requirements.txt and restart. No model downloads.

Prefer V2 over the original for the background_color control unless you have no letterbox padding to color. The one setting to be careful with is fit: use letterbox when you must keep the whole image, crop when you can trade edge pixels for a full frame, and steer clear of fill unless deliberate stretching is what you want - a squashed composite is the most obvious sign a resize went sideways. And the recurring LayerStyle warning: if this node never appears after installing the pack, the pack failed to import on a Python dependency conflict (its trademark failure), so check the console, run "Try Fix" in Manager, and reinstall the requirements.

Category😺dzNodes/LayerUtility

Inputs (6)

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

Outputs (5)

NameTypeDescription
imageIMAGE—
maskMASK—
original_sizeBOX—
widhtINT—
heightINT—