Nodes/ComfyUI Layer Style/LayerUtility: RoundedRectangle
ComfyUI Node Runs on cloud

LayerUtility: RoundedRectangle

RoundedRectangle — build a rounded-corner mask, optionally around an object

By chflame163·Created 3 years ago·Updated 4 days ago· 3,113
LayerUtility: RoundedRectangle
  • image
  • object_mask
  • crop_box
  • image
  • mask
â—„rounded_rect_radius50â–º
â—„anti_aliasing2â–º
â—„top8.0â–º
â—„bottom8.0â–º
â—„left8.0â–º
â—„right8.0â–º
◄detect▾►
â—„obj_ext_top8.0â–º
â—„obj_ext_bottom8.0â–º
â—„obj_ext_left8.0â–º
â—„obj_ext_right8.0â–º

Need a rounded-corner shape - a card, a UI frame, a rounded crop, a soft-cornered mask to composite through? This node builds one. At its simplest it draws a rounded rectangle. Its actual trick is that it can derive that rectangle from an object's mask: give it the mask of a subject and it figures out a bounding rectangle around it, rounds the corners, and hands you both the shape as an image and as a mask.

That makes it handy for layout and framing work - sticker cards where the subject sits in a rounded panel, thumbnail frames, rounded product crops, anywhere a hard rectangle looks cheap and a rounded one looks designed.

How it works

Two modes, really. Without an object mask, it draws a rounded rectangle sized by the edge insets. With an object_mask, the detect setting decides how it fits the rectangle to the object - the tightest box, the smallest enclosing box, or the largest box that fits inside the shape - and the obj_ext_* controls let you pad that box out past the object so it isn't cropping right at the edges. Then it rounds the corners by your radius.

The inputs and outputs that matter

  • rounded_rect_radius (0–100) - corner roundness as a percentage. 0 is a sharp rectangle, 100 is as round as the shape allows.
  • detect - mask_area, min_bounding_rect, or max_inscribed_rect. How the rectangle is fitted to the object_mask. If you're wrapping a subject, min_bounding_rect is the intuitive one.
  • obj_ext_top / _bottom / _left / _right - pad the detected box outward so the subject has breathing room inside the frame.
  • top / bottom / left / right - edge insets for the plain (no-object) case.
  • anti_aliasing - smooth the rounded corners.
  • Optional object_mask and crop_box to drive the fit.

Outputs: the shape as an image and as a mask.

How to install it

Ships in the LayerStyle pack. ComfyUI Manager → search LayerStyle → install → restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/chflame163/ComfyUI_LayerStyle
pip install -r ComfyUI_LayerStyle/requirements.txt

then restart. Under 😺dzNodes → LayerUtility. No model download.

Common issues & troubleshooting

The corners barely look rounded. On a large rectangle, a low rounded_rect_radius percentage is a small absolute radius. Push the value up, and turn on anti_aliasing so the curve isn't jagged.

The rectangle doesn't hug my subject. That's the detect mode plus the obj_ext_* padding. Try min_bounding_rect for a tight wrap, and use the extend values to give margin. max_inscribed_rect does the opposite - it fits inside the shape, which surprises people expecting an enclosing box.

Nothing detects. The object-aware modes need an object_mask wired in. Without one, you're in plain-rectangle mode and only the edge insets apply.

Node missing from the menu. The LayerStyle pack didn't import - commonly a broken transformers dependency (a stray TensorFlow) crashing the whole pack on load. Check the traceback, use Manager's "Try Fix," or repair the offending library.

Category😺dzNodes/LayerUtility

Inputs (14)

NameTypeDefaultDescription
imageIMAGE—
rounded_rect_radiusINT500–100—
anti_aliasingINT20–16—
topFLOAT8.0-100–100—
bottomFLOAT8.0-100–100—
leftFLOAT8.0-100–100—
rightFLOAT8.0-100–100—
detectCOMBO3 options: mask_area, min_bounding_rect, max_inscribed_rect
obj_ext_topFLOAT8.0-100–100—
obj_ext_bottomFLOAT8.0-100–100—
obj_ext_leftFLOAT8.0-100–100—
obj_ext_rightFLOAT8.0-100–100—
object_maskoptMASK—
crop_boxoptBOX—

Outputs (2)

NameTypeDescription
imageIMAGE—
maskMASK—