Nodes/ComfyUI Layer Style/LayerUtility: Image Composite Handle Mask
ComfyUI Node Runs on cloud

LayerUtility: Image Composite Handle Mask

Image Composite Handle Mask

By chflame163·Created 3 years ago·Updated 4 days ago· 3,113
LayerUtility: Image Composite Handle Mask
  • background_image
  • layer_image
  • layer_mask
  • image
  • mask
  • layer_bbox_mask
  • handle_mask
  • handle_crop_box
  • handle_overrange
â—„invert_masktrueâ–º
â—„opacity100â–º
â—„x_percent50.00â–º
â—„y_percent50.00â–º
â—„scale1.000â–º
â—„rotate0.00â–º
◄mirror▾►
â—„anti_aliasing0â–º
◄handle_detect▾►
â—„top_handle0.30â–º
â—„bottom_handle0.30â–º
â—„left_handle0.30â–º
â—„right_handle0.30â–º
â—„handle_mask_outradius128â–º
â—„top_reserve0â–º
â—„bottom_reserve0â–º
â—„left_reserve0â–º
â—„right_reserve0â–º
◄round_to_multiple▾►

This is the power-user compositor. It does everything ImageBlendAdvance does - place a layer on a background with scale, rotation, mirror, and opacity - but it also generates a set of "handle" masks around the placed layer, which is the whole reason it exists. Those handles are the feathered border region just outside your subject, and they're exactly what you need when the next step is fixing the seam: blending a composite into its background, inpainting the transition, or giving a relight model room to wrap light around the edge. If your composites look pasted-on, the handle mask is the tool for making them not look pasted-on.

Here's the idea. When you drop a cut-out onto a new background, the hard part isn't the placement, it's the boundary - the halo, the missing contact shadow, the too-sharp edge. This node places the layer and then hands you a mask of the transition zone so you can process it separately. You composite, then run an inpaint or a blur or a relight only on the handle region, and the seam disappears.

The placement controls mirror ImageBlendAdvance: x_percent/y_percent for position, scale, rotate, mirror, opacity, anti_aliasing, and invert_mask (default true). The handle-specific controls are where it gets interesting. handle_detect chooses whether the handles are measured from the mask area or the layer's bounding box. top_handle, bottom_handle, left_handle, and right_handle set how far the handle extends on each side (as a multiplier, 0–5), so you can feather more on the side that needs it. handle_mask_outradius controls the outer softness of the handle band. And top/bottom/left/right_reserve plus round_to_multiple (8, 16, 32… up to 512, or None) let you pad the composite region and snap its dimensions to a clean multiple - which matters if you're feeding the result into a model that wants dimensions divisible by 8 or 64.

The outputs are a toolbox: image (the composite), mask (the layer mask), layer_bbox_mask (the layer's bounding box as a mask), handle_mask (the feathered border region - the star of the show), handle_crop_box (a BOX for cropping to the handle area), and handle_overrange, a string flag telling you whether the handles ran past the image bounds. Wire handle_mask into your seam-fixing step and handle_crop_box into a crop if you want to process the transition at full resolution.

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 needed.

Honest take: this node has a lot of dials and it's overkill for a simple paste - if you don't need the handle masks, ImageBlendAdvance is less to think about. But when you're building a real composite that has to survive scrutiny, the handle mask is the difference-maker, and doing it in one node beats hand-building the feathered border yourself. Watch the handle_overrange output; if it flags, your handles are spilling off the canvas and you should shrink them or add reserve. And the standing LayerStyle warning: if the node won't load, the pack hit an import error (its signature dependency-conflict failure) - console, "Try Fix," reinstall requirements.

Category😺dzNodes/LayerUtility

Inputs (22)

NameTypeDefaultDescription
background_imageIMAGE—
layer_imageIMAGE—
invert_maskBOOLEANtrue—
opacityINT1000–100—
x_percentFLOAT50.00-999–999—
y_percentFLOAT50.00-999–999—
scaleFLOAT1.0000.001–10000—
rotateFLOAT0.00-360–360—
mirrorCOMBO3 options: None, horizontal, vertical
anti_aliasingINT00–8—
handle_detectCOMBO2 options: mask_area, layer_bbox
top_handleFLOAT0.300–5—
bottom_handleFLOAT0.300–5—
left_handleFLOAT0.300–5—
right_handleFLOAT0.300–5—
handle_mask_outradiusINT1288–9999—
top_reserveINT0-9999–9999—
bottom_reserveINT0-9999–9999—
left_reserveINT0-9999–9999—
right_reserveINT0-9999–9999—
round_to_multipleCOMBO8 options: 8, 16, 32, 64, 128, 256, +2
layer_maskoptMASK—

Outputs (6)

NameTypeDescription
imageIMAGE—
maskMASK—
layer_bbox_maskMASK—
handle_maskMASK—
handle_crop_boxBOX—
handle_overrangeSTRING—