ComfyUI Node Runs on cloud

Resize Mask

Match a mask to your image, without the gray fringe

By kijai·Created 3 years ago·Updated a day ago· 2,908
Resize Mask
  • mask
  • mask
  • width
  • height
width512
height512
keep_proportionsfalse
upscale_method
crop

This is the node you reach for the moment ComfyUI complains that your mask and your image are different sizes. Masks have to line up pixel-for-pixel with whatever they're modifying - a latent, an image, a conditioning region - and the second you load a mask from a different source, or upscale midway through a graph, the dimensions stop matching. Resize Mask fixes that, and it does one small extra thing that turns out to be the whole reason to use this one over a generic resize: it tells you the size it produced.

It's part of KJNodes, kijai's big grab-bag of utility and QoL nodes. Kijai is one of the most prolific people in the ComfyUI ecosystem - he wrote a lot of the video-model plumbing everyone runs - and this pack is where the small tools live. Odds are you already have it installed for something else.

How it works

You give it a mask and a target width and height, and it resamples the mask to those dimensions using the interpolation method you pick. The catch that bites people is which interpolation. A mask is often meant to be crisp - pure black and white - and if you resize it with a smoothing method you get gray pixels along every edge. Sometimes that soft feather is exactly what you want. Sometimes it quietly ruins a hard-edged inpaint mask.

The inputs that matter

  • mask, width, height - the obvious three. Set the target dimensions to match whatever the mask has to align with.
  • upscale_method - the important one. nearest-exact keeps a binary mask crisp (no gray fringe); bilinear, bicubic, and lanczos smooth the edges (good for soft masks you want feathered); area is the clean choice when you're shrinking.
  • keep_proportions - fits the mask inside the target without stretching, so a mask made at a different aspect ratio doesn't get squashed.
  • crop - set to center to crop to the target aspect instead of distorting.

Outputs are the resized mask plus its final width and height as integers. Those two ints are the underrated part - wire them into a downstream resize or a "same size as" input and the rest of your graph stays in sync automatically instead of you hardcoding numbers.

Installing it

ComfyUI Manager → Install Custom Nodes → search KJNodes for ComfyUI → install → restart. Or manually: cd ComfyUI/custom_nodes && git clone https://github.com/kijai/ComfyUI-KJNodes, then pip install -r ComfyUI-KJNodes/requirements.txt (portable builds: python_embeded\python.exe -m pip install -r ComfyUI\custom_nodes\ComfyUI-KJNodes\requirements.txt), and restart. The pack keeps dependencies deliberately light, so this one has nothing heavy behind it.

Where people get burned

  • Gray edges on a binary mask. If you resized with bilinear and your inpaint now bleeds at the boundary, that's the smoothing adding half-tones. Switch to nearest-exact for a mask that has to stay hard.
  • Squashed masks. No keep_proportions plus a different target aspect ratio stretches the shape. Turn it on, or use crop: center, when the mask was made at another ratio.
  • Resizing when you didn't need to. If a mask and image are already the same size, this node is a no-op cost - it's a fixer, not a mandatory step. Insert it where sizes actually diverge.
CategoryKJNodes/masking

Inputs (6)

NameTypeDefaultDescription
maskMASK
widthINT5120–16384
heightINT5120–16384
keep_proportionsBOOLEANfalse
upscale_methodCOMBO5 options: nearest-exact, bilinear, area, bicubic, lanczos
cropCOMBO2 options: disabled, center

Outputs (3)

NameTypeDescription
maskMASK
widthINT
heightINT