Nodes/ComfyUI-CustomNodePacks/Layer Effect: Stroke (MEC)
ComfyUI Node

Layer Effect: Stroke (MEC)

A stroke ring that's also its own mask

By Code2Collapse·Created 7 months ago·Updated 2 days ago· 56
Layer Effect: Stroke (MEC)
  • layer_image
  • background_image
  • layer_mask
  • image
  • effect_mask
  • report
invert_masktrue
blend_mode
opacity100
stroke_grow0
stroke_width8
blur0
stroke_color#FF0000
dissolve_seed0

What it is

An outline around the subject: the sticker border, the label rim, the selection ring, the graphic halo on a thumbnail. And - more usefully than that sounds - a band matte: effect_mask here is the ring itself, which is exactly the region you'd want to grade, glow, or grain independently.

This is one of eight layer effects ported into this pack from chflame163's ComfyUI_LayerStyle, rewritten torch-native and standalone. Worth knowing if you've read anything about upstream: it's a several-hundred-node pack with a dependency list to match and some nodes that call out to Google's API if given a key, which made more than one community thread ask whether installing it was wise. Eight effects don't need that.

How the ring is built

The stroke is a difference of two grown mattes:

  • inner_stroke = stroke_grow − stroke_width / 2
  • outer_stroke = inner_stroke + stroke_width

Both are grown from the layer matte and blurred by blur, and the ring is the outer minus the inner. That's upstream's "inner stroke / outer stroke" split collapsed into one node: stroke_grow slides the ring in and out - negative pulls it inside the subject, positive pushes it outside - while stroke_width sets how thick it is. Blur is applied to both mattes before the subtraction, so a non-zero blur softens both edges of the band rather than just the outside.

The stroke colour is blended onto a copy of the layer using your blend_mode and opacity, and that result is pasted through the ring matte on top of the layer, which is then composited onto the plate via the layer matte. So the stroke sits over the subject, which is what you want for a rim and slightly wrong if you wanted the outline to go under the shape.

Inputs

  • layer_image, and layer_mask (optional) - you need one of these to define the subject; a 3-channel image with no mask raises needs a layer mask.
  • invert_mask - defaults to true and really inverts. A standard white-on-subject matte plus the default = the ring traces the background. Flip it before you debug anything else.
  • stroke_grow - default 0, range −999 to 999. The position of the ring relative to the matte edge.
  • stroke_width - default 8. Ring thickness.
  • blur - default 0, range 0–100. Zero gives the crisp graphic look; 2–6 gives a soft rim.
  • stroke_color - default #FF0000, which tells you the author expected you to change it immediately.
  • blend_mode (30 modes), opacity, dissolve_seed - dissolve is stochastic and seeded here, so it holds still across a sequence where upstream's per-frame reseed flickered.

Optional background_image is the plate; leave it empty and you're drawing on a transparent canvas, i.e. black where nothing was drawn.

Outputs: image, effect_mask (the ring), report.

What to actually do with it

For a graphic outline: blur 0, stroke_grow +2, stroke_width 4–8, opacity 100, normal. That's the sticker.

For a rim light, which is the more interesting use: stroke_grow −3 (so the ring sits inside the silhouette), stroke_width 12, blur 4–8, screen, opacity 50–70, and a light colour. That reads as edge lighting rather than an outline.

Then take effect_mask and do something with it: multiply it into an exposure grade, use it to drive a bloom or grain pass, or feed it to Inpaint Crop Pro (MEC) if you want to regenerate just the edge region. A ring matte is a surprisingly handy shape to have as a first-class output, and most stroke implementations only give you the flattened picture.

Install

ComfyUI Manager → search "CustomNodePacks", or:

cd ComfyUI/custom_nodes
git clone https://github.com/Code2Collapse/ComfyUI-CustomNodePacks

Restart and check the console for the pack's load line. Required pack dependencies are opencv-python, scipy, safetensors; this node is tier 1 (no models, no VRAM). The README asks you to check pip list first rather than running pip install -r requirements.txt - it lists packages ComfyUI already provides, and overwriting torch is a genuinely bad afternoon.

Common issues

  • The ring is on the background, not the subject. invert_mask.
  • The ring has a hard inner edge and a soft outer one. That's blur doing what it does to both mattes; if you want a uniform softness, blur less and feather the matte upstream instead.
  • The ring vanishes on a tight matte. A large negative stroke_grow with a wide stroke_width pushes the whole band outside the matte and off into the clipped region. Reduce the grow.
CategoryMEC/LayerEffects

Inputs (11)

NameTypeDefaultDescription
layer_imageIMAGE
invert_maskBOOLEANtrue
blend_modeCOMBO30 options: normal, dissolve, darken, multiply, color burn, linear burn, +24
opacityINT1000–100
stroke_growINT0-999–999
stroke_widthINT80–999
blurINT00–100
stroke_colorSTRING#FF0000
dissolve_seedINT00–2147483647Only used by the 'dissolve' blend mode. Upstream reseeds every frame, so a dissolve flickers through a sequence; a fixed seed here holds still.
background_imageoptIMAGE
layer_maskoptMASK

Outputs (3)

NameTypeDescription
imageIMAGE
effect_maskMASK
reportSTRING