Nodes/ComfyUI Layer Style/LayerMask: Mask Box Extend
ComfyUI Node Runs on cloud

LayerMask: Mask Box Extend

Mask Box Extend

By chflame163·Created 3 years ago·Updated 4 days ago· 3,113
LayerMask: Mask Box Extend
  • mask
  • crop_box
  • mask
  • x_percent
  • y_percent
  • width
  • height
  • x
  • y
  • crop_box
â—„top_extend10.0â–º
â—„bottem_extend10.0â–º
â—„left_extend10.0â–º
â—„right_extend10.0â–º

This is a helper node for the crop-and-paste workflow, and it's not one you reach for on its own. Its job is to take a crop box that was computed from a mask - the kind CropByMask spits out - and nudge its edges outward or inward by a per-side amount, then report back the adjusted geometry. If you've ever cropped tight to a subject for detailing and then found the crop clipped the hair or left no room for a shadow, this is the node that fixes the box without you eyeballing pixel coordinates.

To make sense of it you have to know the pattern it lives in. Nodes like CropByMask detect a subject's bounding region and output a crop_box (type BOX) describing where that region sits in the full image. You crop, do your work at high detail, and paste back using that same box. MaskBoxExtend sits in the middle: it takes the mask and the crop_box, extends the box by the amounts you give per side, and recomputes all the positioning numbers so the downstream paste lands correctly.

The inputs are four extend amounts - top_extend, bottem_extend (yes, the pack spells it that way), left_extend, and right_extend. Positive values push that edge of the box outward to include more surrounding area; negative values pull it in. That's it for what you set; the mask and crop_box come from upstream.

What comes back out is a bundle of geometry, and that's the actual value of the node. mask is the adjusted mask, crop_box is the new extended box to feed the paste-back step, and then a set of raw numbers describing it: x and y (the box's top-left corner), width and height (its size), and x_percent / y_percent (its center as a percentage, which is the coordinate format the pack's composite nodes like ImageBlendAdvance expect). That last pair is the reason this node exists - it hands you positioning in exactly the form the blend nodes want, so you don't do the arithmetic yourself.

Install is the pack standard: search "ComfyUI Layer Style" in ComfyUI Manager, or cd ComfyUI/custom_nodes && git clone https://github.com/chflame163/ComfyUI_LayerStyle, then pip install -r requirements.txt and restart. No models - it's pure geometry.

Honest take: this is plumbing, not a headline node, and it only makes sense wired between a crop and a composite. If you're not already working with BOX outputs from CropByMask (V2/V3), you don't need it. And the standard LayerStyle warning holds - if it or its neighbors don't show up after install, the pack failed to import on a dependency conflict, which is the pack's signature failure mode; check the console, "Try Fix" in Manager, reinstall requirements. Once you're doing crop-based detail work, though, having the box math done for you and returned in the blend nodes' native coordinate system is genuinely handy.

Category😺dzNodes/LayerMask

Inputs (6)

NameTypeDefaultDescription
maskMASK—
crop_boxBOX—
top_extendFLOAT10.0-9999–9999—
bottem_extendFLOAT10.0-9999–9999—
left_extendFLOAT10.0-9999–9999—
right_extendFLOAT10.0-9999–9999—

Outputs (8)

NameTypeDescription
maskMASK—
x_percentFLOAT—
y_percentFLOAT—
widthINT—
heightINT—
xINT—
yINT—
crop_boxBOX—