Nodes/ComfyUI Extended/Crop Image To Mask
ComfyUI Node

Crop Image To Mask

Crop an image down to just the masked region — the face-fix workflow's opening move

By rookiepsi·Created about a year ago·Updated 11 months ago· 9
Crop Image To Mask
  • image
  • mask
  • IMAGE
padding0

The classic trick for fixing a face in a large image is to crop it, regenerate it bigger and cleaner, and paste it back. Crop Image To Mask is the first half of that pipeline: it takes an image and a mask, finds the mask's bounding box, and returns just that region of the image - with optional padding around it.

It's from ComfyUI Extended, and it's a genuinely useful building block for inpaint-and-paste workflows, where Impact Pack-style face detailers are overkill and you want to do it by hand.

How it works

Three inputs:

  • image (IMAGE) - the source.
  • mask (MASK) - defines the region to keep. The node finds every pixel above zero, computes the bounding box, and crops to it.
  • padding (INT, −8192 to 8192, default 0) - extra pixels around the crop. Positive grows it, negative shrinks it, and it clamps to the image edges so you can't crop past the border.

The output is the cropped IMAGE. Two behaviors are worth knowing: if the mask is empty, the original image passes through untouched; and if you feed a batch of image/mask pairs, each one is cropped to its own mask and then all crops are padded (with black) to the largest size so they stay in one tensor.

Install

cd /path/to/your/ComfyUI/custom_nodes
git clone https://github.com/rookiepsi/comfyui-extended.git

Restart ComfyUI; it's under comfyUI-extended/image in the node menu. Or ComfyUI Manager → search "ComfyUI Extended" → install → restart. No models, no pip dependencies.

Common issues

  • It returns only the crop - no coordinates. This node gives you the cropped image and nothing else. If your plan is to paste the result back into the original at the same spot, you need to track where the crop came from yourself (or use a node that also reports the bounding box). For the "crop → upscale → paste back" flow, plan the bookkeeping.
  • Black padding in batches. Mixed-size crops in one batch get zero-padded to the largest - the seams are black, not edge-sampled. Fine for most uses, surprising if you're comparing crops side by side.
  • Empty mask = full image. No mask content, no crop. Your downstream node gets the whole image back, so guard against accidentally-empty masks if you're feeding this from a detector.

Where it fits: any "regenerate a region at higher quality" workflow, or cropping to a subject for a focused pass before reinserting. It's the workhorse step - just remember it hands you the crop, not the map.

CategorycomfyUI-extended/image

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
maskMASK
paddingINT0-8192–8192

Outputs (1)

NameTypeDescription
IMAGEIMAGE