ComfyUI Node

Crop Image By Mask

Crop an image down to whatever your mask marks black

By thalismind·Created about a year ago·Updated about a year ago· 8
Crop Image By Mask
  • image
  • mask
  • image
  • mask

Quick heads-up before anything else: this node isn't in the pack's own README. LoadImageWithFilename, LoadImageFolder and SaveImageWithFilename all get a section there; CropImageByMask ships in the same file but doesn't get a mention. So take the description below as read straight off the node's own schema and tooltips - it's accurate to what the node reports about itself, there's just no author commentary to lean on beyond that.

What it does

It crops an image (and its mask) down to whatever region the mask marks as black. That's the part to actually pay attention to, because it's backwards from how a lot of ComfyUI masking works: in most inpainting-flavored nodes, white (1.0) is the "selected, do something here" region and black (0.0) is background you leave alone. This node inverts that convention explicitly - its own tooltip says it: white pixels get excluded, black pixels get included. Feed it a normal "paint white over the subject" mask expecting it to crop to that subject, and you'll get the opposite of what you wanted.

The mechanism, in plain terms: it looks at where your mask is black, and trims the image (and the mask that goes with it) down to just that area, discarding the rest of the canvas. Think of it as a "cut to content" step rather than the full crop-and-stitch machinery you'd find in a dedicated inpainting pack - there's no companion "stitch it back" node here, no context padding controls, no resize handling. It's a blunt, single-purpose crop.

The inputs and outputs that matter

Only two inputs, both required:

  • image (IMAGE) - the image to crop.
  • mask (MASK) - the mask that decides the crop region. Per the node's own tooltip: white (1.0) excluded, black (0.0) included.

Two outputs:

  • image (IMAGE) - the cropped image.
  • mask (MASK) - the cropped mask, trimmed down alongside the image.

Installing it

Same pack, same install path as the rest:

  • ComfyUI Manager - search ComfyUI LoadImageWithFilename, install, restart.
  • Manual - cd ComfyUI/custom_nodes && git clone https://github.com/thalismind/ComfyUI-LoadImageWithFilename, restart ComfyUI.

It's part of the same single nodes.py file as the load/save nodes, so there's nothing extra to fetch - no models, no separate dependencies beyond the PIL/PyTorch/NumPy baseline every ComfyUI install already has. It'll show up in the image category once ComfyUI restarts.

Common issues

The inverted mask polarity is the whole ballgame here. If your mask came from a segmentation node, SAM, or anything else that follows the "white = subject" convention, invert it first with a core InvertMask node before wiring it in - otherwise you'll get a crop of the background instead of the thing you wanted. This is genuinely the most likely way to get confused by this node, and there's no toggle on the node itself to flip that behavior, so the invert has to happen upstream.

Keep the image and mask sized to match. Mask-driven crop nodes across ComfyUI generally expect the mask to correspond pixel-for-pixel to the image it's cropping, and there's nothing in this node's schema suggesting it does any resizing to reconcile a mismatch - so if your mask came from a different resolution pipeline, resize it to match the image first.

This is a plain crop, not an inpainting workflow. If what you actually want is to isolate a region, edit it, and blend it back into the original image, this node only gets you the first step. It doesn't stitch anything back - pair it with your own compositing step, or look at a dedicated crop-and-stitch node pair if you need the round trip.

Categoryimage

Inputs (2)

NameTypeDefaultDescription
imageIMAGEThe image to crop
maskMASKThe mask to use for cropping. White pixels (1.0) will be excluded, black pixels (0.0) will be included.

Outputs (2)

NameTypeDescription
imageIMAGE
maskMASK