ComfyUI Node

Mask Crop

Cuts the painted area out of a picture with room to spare, in a size a sampler will accept. pad_* are multipliers of the painted area's short side, so 1.4 adds 40% of it on that side and 1.0 hugs the paint. size_mode native keeps the composed size, square pads it out to a square, custom frames it to custom_width x custom_height (0 on one side derives it from the other). multiple rounds the result up to a whole number (8 keeps latent sizes legal). Whatever still hangs outside the picture is filled from its own edge colours. Feed the seam output to Crop Restore to paste a processed crop back in place.

By live1617·Created 21 days ago·Updated 2 days ago· 3
Mask Crop
  • image
  • mask
  • seam
  • image
  • mask
◄size_modenative►
◄custom_width1024►
◄custom_height1024►
◄multiple8►
◄pad_top1.40►
◄pad_right1.40►
◄pad_bottom1.40►
◄pad_left1.40►
◄fill_holesfalse►
◄filledge►
CategoryQG-tools/Mask

Inputs (12)

NameTypeDefaultDescription
imageIMAGEThe picture to cut from.
maskMASKWhat to keep in frame. The whole batch shares the union of every frame's painted area.
size_modeCOMBOnativenative: the composed size. square: padded out to a square. custom: framed to the size below.
custom_widthINT10240–8192custom only. 0 means derive it from custom_height and the composed aspect.
custom_heightINT10240–8192custom only. 0 means derive it from custom_width and the composed aspect.
multipleINT81–256Round the crop up to a whole multiple of this. 8 keeps latent sizes legal; 1 disables it.
pad_topFLOAT1.401–4Room above the paint, as a multiplier of its short side. 1.0 hugs it.
pad_rightFLOAT1.401–4Room to the right, same unit.
pad_bottomFLOAT1.401–4Room below, same unit.
pad_leftFLOAT1.401–4Room to the left, same unit.
fill_holesBOOLEANfalseFill the gaps the paint closes all the way round before measuring it, so a bracelet or a window does not shrink the frame.
fillCOMBOedgeHow the room outside the picture gets painted: edge takes each side's most common colour, stretch repeats its outer row or column, black leaves it empty.

Outputs (3)

NameTypeDescription
seamQGSeamEverything Crop Restore needs to put the result back: the source picture, the rectangle and the size it was cut at.
imageIMAGEThe crop, ready for an upscale or a repaint.
maskMASKThe same crop's mask. Empty where the crop reaches outside the picture.