ComfyUI Node

Mask-Crop | Pre

Crop to a mask without the resize — for inpainters who bring their own pipeline

By wmpmiles·Created 2 years ago·Updated about a year ago· 5
Mask-Crop | Pre
  • image
  • mask
  • image
  • mask
  • context
squaretrue
area_mult1.0

Mask-Crop | Pre is the stripped-down cousin of Mask-Crop Inpaint | Pre: it crops image and mask to a bounding box around your mask and hands them over - but it does no resizing, no color shifting, no padding. It's for the workflow where you don't want the pack deciding the crop's target size, because you're feeding a tool that wants to do that itself.

The "why" is the interesting part. The full Inpaint Pre node resizes the crop to a model-friendly resolution because it's designed for classic mask-inpainting pipelines. But there are setups where you don't want a resize baked in: you're using a model or a node that handles arbitrary input sizes, you're chaining the crop into a different node (a ControlNet preprocessor, an upscaler, a manual sampler), or you want to inspect the crop before anything else happens to it. This node gives you the crop and nothing else, and pairs with Mask-Crop | Post to paste it back.

Inputs and outputs

Inputs are image, mask, square (BOOLEAN, default true), and area_mult (FLOAT, default 1, min 1). Same semantics as the Inpaint version: square forces the bounding box to be square, area_mult expands it (1 hugs the mask, 1.5–2 gives breathing room). Outputs are image, mask (both cropped, at their original resolution - no resize happened), and context, which Mask-Crop | Post needs to place the result back on the full canvas.

The mask has to be a single batch and match the image resolution - the node validates both and errors clearly if not. It computes the box with bbox_from_2d_binary, so any nonzero mask pixel defines the region.

The trade you're making

You get total control over what happens between Pre and Post, and you pay for it in responsibility. The Inpaint pair is a complete, tested pipeline; this pair is a manual one. The gap you're filling is the resize - so if you crop with this and then try to run the crop through a sampler, you're on the hook for resizing it to something the model handles well (multiple of 8, reasonable aspect ratio, right native ballpark). That's what Resample Image and the pack's scalers are for, and they compose fine between Pre and Post. If that sounds like work you'd rather not do, the Inpaint variant was built for you.

Installing

Part of comfyui-some-image-processing-stuff:

cd ComfyUI/custom_nodes
git clone https://github.com/wmpmiles/comfyui-some-image-processing-stuff

Restart ComfyUI, or ComfyUI Manager → search "Some Image Processing Stuff". No models, no dependencies. It's the lightest node in the inpaint family, but it's the one to reach for when you're building something custom and you just need a clean, exact crop around a mask.

Categoryinpaint

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
maskMASK
squareBOOLEANtrue
area_multFLOAT1.0

Outputs (3)

NameTypeDescription
imageIMAGE
maskMASK
contextCONTEXT