Nodes/ComfyUI-TextureAlchemy/Simple Crop to Mask (with Padding) ⚡
ComfyUI Node

Simple Crop to Mask (with Padding) ⚡

Giving your inpaint a bit of room to breathe

By amtarr·Created 9 months ago·Updated 4 months ago· 58
Simple Crop to Mask (with Padding) ⚡
  • image
  • mask
  • cropped_image
  • cropped_mask
  • masked_composite
  • bbox_data
  • info
padding50
pad_to_squarefalse
padding_colorblack
custom_color#000000
invert_maskfalse

The simplest version of inpainting fails in a predictable way: you crop tightly to the mask, the model has zero context, and the result ignores the surrounding material. Simple Crop to Mask (with Padding) fixes that by letting you decide how much of the world around the mask comes along for the ride - and what fills the space in between.

How it works

It finds the mask's bounding box, crops the image and mask to it, then expands the canvas outward by padding pixels (default 50). The interesting part is padding_color, which controls what that expanded border contains:

  • black / white - solid fills, simple but they introduce a hard artificial edge the model can lean on.
  • mirror - reflects the crop edges outward, so the border is a continuation of the texture. Usually reads the most natural.
  • edge_extend - stretches the edge pixels, good for flat colors and gradients.
  • from_crop - takes the border from elsewhere in the tight crop.
  • use_image - the special one: with pad_to_square on, it grabs a square window from the full input image centered on the mask, so you get real surrounding context instead of padding. That's the "give the model actual neighbors" mode.
  • average - fills with the crop's average color, which keeps the border neutral.
  • custom - any hex color you type into custom_color.

pad_to_square expands the crop to a square canvas (using the longest dimension) - useful if your downstream model wants square inputs. And invert_mask swaps which side of the mask is "the thing."

The outputs

You get cropped_image, cropped_mask, a masked_composite (crop with the mask applied, for a quick look), plus bbox_data and an info string. The bbox bundle is what makes the sibling Simple Inpaint Stitch one wire away: crop here, edit the crop, stitch it back at these exact coordinates.

Installing it

In amtarr/ComfyUI-TextureAlchemy - ComfyUI Manager "Texture Alchemy", or:

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

Restart, then right-click → Add Node → Texture Alchemist → Inpainting → Simple. No extra dependencies, no models.

Where people get burned

Solid black padding is the trap: a model that's fine inpainting on a mirror border can hallucinate against a hard black frame, and it creates a visible step when you stitch. Prefer mirror or use_image + pad_to_square when the mask is near an edge. Also, this crop keeps everything in the original resolution - if the masked region is tiny, you'll want to upscale the crop before sampling so the model gets enough pixels to work with (masked inpainting's superpower is full-res detail on a small region). The pack prints a console banner every run; that's normal.

CategoryTexture Alchemist/Inpainting/Simple

Inputs (7)

NameTypeDefaultDescription
imageIMAGE
maskMASK
paddingINT500–500Padding in pixels (expands canvas)
pad_to_squareBOOLEANfalseExpand to square canvas (uses longest dimension)
padding_colorCOMBOblackuse_image (with pad to square): square crop from the full input, centered on the mask. Other: from_crop/edge/mirror from tight crop; black/white/average/custom = solid/avg
custom_colorSTRING#000000Hex color for custom padding (e.g., #FF5733)
invert_maskBOOLEANfalseInvert mask (swap black/white)

Outputs (5)

NameTypeDescription
cropped_imageIMAGE
cropped_maskMASK
masked_compositeIMAGE
bbox_dataBBOX_DATA
infoSTRING