LayerUtility: RoundedRectangle
RoundedRectangle — build a rounded-corner mask, optionally around an object
- image
- object_mask
- crop_box
- image
- mask
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, ormax_inscribed_rect. How the rectangle is fitted to theobject_mask. If you're wrapping a subject,min_bounding_rectis 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_maskandcrop_boxto 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.
Inputs (14)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| rounded_rect_radius | INT | 500–100 | — |
| anti_aliasing | INT | 20–16 | — |
| top | FLOAT | 8.0-100–100 | — |
| bottom | FLOAT | 8.0-100–100 | — |
| left | FLOAT | 8.0-100–100 | — |
| right | FLOAT | 8.0-100–100 | — |
| detect | COMBO | 3 options: mask_area, min_bounding_rect, max_inscribed_rect | |
| obj_ext_top | FLOAT | 8.0-100–100 | — |
| obj_ext_bottom | FLOAT | 8.0-100–100 | — |
| obj_ext_left | FLOAT | 8.0-100–100 | — |
| obj_ext_right | FLOAT | 8.0-100–100 | — |
| object_maskopt | MASK | — | |
| crop_boxopt | BOX | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |