Layer Trim
Cut the empty band off a cut-out so effects stop wasting radius on it
- layers
- layers
- width
- height
A cut-out that arrives on a full frame of transparency is a trap in disguise. The subject is tiny, the canvas it came on is huge, and every effect that follows - glow, shadow, stroke, blur - spends its pixel radius on empty space instead of the subject. Layer Trim fixes it: it cuts the empty band off a layer's picture and moves x and y in by the same amount, so nothing on the canvas appears to shift. The layer that was a tiny subject on a big frame becomes a layer the size of the subject, sitting exactly where it visually was.
Why that matters
Two concrete payoffs the node description calls out. First, Layer Align centres the subject rather than the frame it arrived on - an untrimmed subject on a lopsided frame aligns wrong, and trimming first makes alignment behave. Second, effects stop throwing their radius at transparency: a 16px glow on a trimmed subject hugs the subject; on an untrimmed frame it also washes 16px of empty space around it, which doubles the effective blur cost and softens the result you actually wanted.
Trimming is also honest about size. Want to know the subject's real footprint? Trim it and read width/height off the outputs.
The controls
scope-one layertrims the layerindexorlayer_namepicks;every layertrims them all, which tidies a whole set of cut-outs in one node.threshold- coverage at or below which a pixel counts as empty. 0.0 keeps every pixel that isn't fully transparent; 0.05 also drops the faintest fringe a soft cut-out leaves (the anti-halo setting); 0.5 starts eating into the edge itself, which is almost never what you want.padding- pixels of the empty band kept on every side. 0 trims flush; 16 leaves a border around the subject that gives a later glow or shadow room before it grows the layer.
That padding knob is the one people discover late and love: trim to the subject, keep a small gutter, and now the glow node has somewhere to draw without first re-growing the layer's canvas by its whole radius. Flush-trimmed layers force effects to expand the layer immediately; padded ones let the effect breathe inside existing pixels.
Installing it
Part of WAS Node Suite:
cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui.git
or ComfyUI Manager → "WAS Node Suite v3", then restart. Requires ComfyUI 0.14.0+ and Python 3.10+; v3 installs no pip packages.
Where people trip
The big one is threshold. A cut-out with a soft anti-aliased edge and threshold at 0.0 keeps those faint edge pixels, so the trim lands a hair outside the visible subject; bump to ~0.05 and the fringe goes with the transparent band. Crank it to 0.5 and you're shaving the subject itself - the "cuts into the edge" warning is literal. Second, trimming changes the layer's stored x/y by design, so nothing appears to move - but that means any downstream node reading the layer's raw coordinates (say, from Layers Info) now sees the shifted values. If you're doing coordinate math, trim first and read positions after.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| layers | LAYERS | The stack holding the layer to trim. Wire in Add Layer, Layer Mask or anything else answering a LAYERS document. | |
| scope | COMBO | How many layers are trimmed. `one layer` trims the one index or layer_name picks; `every layer` trims them all, which tidies a whole set of cut-outs in one node. | |
| index | INT | -1-16384–16384 | Which layer is trimmed, counting 0 from the back of the stack. -1 is the front layer. Ignored while layer_name names one, or on `every layer`. |
| layer_name | STRING | Name of the layer to trim instead of index. Blank uses index. 'sky' finds a layer called Sky, and finds Sky Backdrop where nothing is called exactly Sky. | |
| threshold | FLOAT | 0.000–1 | Coverage at or below which a pixel counts as empty. 0.0 keeps every pixel that is not fully transparent, 0.05 also drops the faintest fringe a soft cut-out leaves, 0.5 cuts into the edge itself. |
| padding | INT | 00–16384 | Pixels of the empty band kept on every side. 0 = trimmed flush, 16 = a 16px border left round the subject, which gives a later glow or shadow room before it grows the layer. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| layers | LAYERS | The stack with the layers trimmed, for Create Layered Image or another edit. |
| width | INT | The last trimmed layer's picture width in pixels. |
| height | INT | The last trimmed layer's picture height in pixels. |