Nodes/ComfyUI Level Pixel/Resize Image and Masks [LP]
ComfyUI Node

Resize Image and Masks [LP]

Keeping an image and its masks in perfect sync

By LevelPixel·Created 2 years ago·Updated 6 months ago· 31
Resize Image and Masks [LP]
  • image
  • mask
  • optional_context_mask
  • image
  • mask
  • optional_context_mask
downscale_algorithmlanczos
upscale_algorithmlanczos
preresize_modeensure minimum resolution
preresize_min_width1024
preresize_min_height1024
preresize_max_width16384
preresize_max_height16384

One honest flag before anything else: this node's own tooltip in ComfyUI describes it as cropping an image around a mask for inpainting - that's a copy-paste leftover from its sibling InpaintCrop-LP's description and doesn't match what this node actually does. Go by the pack's README instead, which covers it properly: this node brings an image, a mask, and an optional context mask - or a whole batch of them - to one consistent target size, all at once, in lockstep.

Why syncing sizes is its own problem

If you resize an image and its mask with two separate nodes, it's easy for them to drift apart by a pixel or two, or for one to use a different algorithm than the other. Feed a sampler an image and mask that don't match dimensions exactly and you get a shape-mismatch error, usually somewhere unhelpfully deep in the stack. This node exists specifically to prevent that: whichever of image, mask, and context mask you wire in get resized together as one operation, so they can't fall out of sync.

It's also useful outside the crop/stitch pipeline - the README notes it works for "special cases of adjusting the size of an image (or mask, or context mask) to the target," meaning you don't need to be doing inpainting at all to find it useful; any workflow that needs an image and mask pair brought to a matching resolution qualifies.

The inputs and outputs that matter

  • image, mask, optional_context_mask - all optional. Whichever you connect gets resized; leaving one unconnected just means it's not part of the operation, it doesn't error.
  • preresize_mode - the real logic here: ensure minimum resolution, ensure maximum resolution, or ensure minimum and maximum resolution. Rather than forcing an exact size, this is a floor and/or ceiling - useful for something like "make sure the short side is at least 1024 for the model to work well, but don't blow past my VRAM budget on the long side," while preserving aspect ratio.
  • preresize_min_width/height and preresize_max_width/height - the actual bounds, all defaulting to a wide-open range (1024 minimum, 16384 maximum) that you'd tighten to your actual model's requirements.
  • downscale_algorithm / upscale_algorithm - both default to lanczos here (note: InpaintCrop-LP defaults to bilinear/bicubic instead - worth knowing if you're used to that node's defaults and expect the same here).

Outputs mirror whichever inputs you fed in: image, mask, optional_context_mask, all resized together.

How to install it

ComfyUI Manager: search "ComfyUI Level Pixel" or ComfyUI-LevelPixel, install, restart - auto-updates through Manager's "Update ALL." Manual:

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

Restart ComfyUI. No models needed, pure image-processing logic (the README credits the same upstream project as InpaintCrop-LP/InpaintStitch-LP for the core functionality here too).

Common issues & troubleshooting

Only some of your inputs came out resized. That's expected behavior, not a bug - only the sockets you actually wired get touched; an unconnected input is simply skipped.

The result looks softer or sharper than you expected. This node's default algorithm is lanczos for both up- and downscaling, which is high quality but not the fastest option. If you're batch-processing a lot of images and speed matters more than the last bit of sharpness, switch to bilinear or nearest.

You expected an exact target resolution, not a min/max range. preresize_mode doesn't work like a hard resize-to-WxH - it's a constraint (at-least, at-most, or both), which preserves aspect ratio rather than forcing a fixed size. If you genuinely need an exact fixed resolution regardless of aspect ratio, this isn't the right mode for it; you'd want a node built for forced dimensions instead, like InpaintCrop-LP's "forced size" mode.

CategoryLevelPixel/Image

Inputs (10)

NameTypeDefaultDescription
downscale_algorithmCOMBOlanczos6 options: nearest, bilinear, bicubic, lanczos, box, hamming
upscale_algorithmCOMBOlanczos6 options: nearest, bilinear, bicubic, lanczos, box, hamming
preresize_modeCOMBOensure minimum resolution3 options: ensure minimum resolution, ensure maximum resolution, ensure minimum and maximum resolution
preresize_min_widthINT10240–16384
preresize_min_heightINT10240–16384
preresize_max_widthINT163840–16384
preresize_max_heightINT163840–16384
imageoptIMAGE
maskoptMASK
optional_context_maskoptMASK

Outputs (3)

NameTypeDescription
imageIMAGE
maskMASK
optional_context_maskMASK