Layer Fit
Scale a layer to cover, fit, or match another
- layers
- layers
- width
- height
Two of the most common composition jobs are, underneath, the same operation: "make this image cover the whole canvas" (a background plate) and "make this badge a fixed height no matter what it arrived as" (an asset on a plate). Both are scale-to-fit - and WAS Layer Fit is the layer-system node that does it without touching the layer's underlying resolution.
Here's the mechanism worth understanding first, because it's the node's whole reason to exist: "Only the drawn size is written, so the layer keeps its full-resolution picture and Create Layered Image resamples it once at the end." A layer in the WAS stack has both a source image and a drawn size. Layer Fit changes the drawn size and leaves the source alone, which means nothing is upscaled or downscaled until the final composite renders - no wasted intermediate resampling, no accumulated blur if you fit, then fit again, then edit.
The three choices that matter:
resize_mode- how the layer reaches its box.fit insidekeeps the whole layer visible with space left over (letterboxing),fill and overflowcovers the box completely and runs past its edges (the background-plate setting - pair it with a crop or let the overflow hide), andstretchtakes the box exactly and distorts the picture. For aspect ratios that don't match,fit insideandfill and overfloware the two honest options;stretchis there for when you truly don't care.against- what it's fitted to.the canvasis the document's own size;a sizeuses thewidth/heightfields you type (the badge-at-fixed-height case);another layerfits to the box thattarget_indexortarget_namedraws in - making one element match another's footprint without knowing either's dimensions.align- where the scaled layer sits inside the box, frommiddle centerto the corners and edges.
index or layer_name picks the layer that moves (0 from the back, -1 the front), and scale is a multiplier applied after the fit: 1.0 is exactly the fit, 0.9 leaves a margin around the whole thing, 1.1 overshoots it. That's the field that turns "fit to canvas" into "fit to canvas with breathing room" without a second node.
Outputs are layers (the stack with the layer scaled and placed, for Create Layered Image or another edit) plus width and height - the pixel size the layer is now drawn at. Those two numbers are the ones worth wiring onward when something else has to match the result, like a shadow sized to the fitted layer rather than to whatever it was before.
This is the natural partner to Layer Align: Align positions, Fit sizes, Edit fine-tunes. Fit a generated background to cover the canvas, fit a badge to a fixed height, or fit one element to another's box - and because nothing resamples until the end, you can chain several of these without paying for it.
Install
Part of WAS Node Suite v3. ComfyUI Manager, search "WAS Node Suite", or:
cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui
Restart after. Needs ComfyUI 0.14.0+ and Python 3.10+, no pip packages or model downloads (v3's install is clean - the old pack's dependency pile is gone).
Common issues
- Layer doesn't fill the frame.
resize_modeis onfit inside- switch tofill and overflowfor a cover. - Everything got distorted.
stretchforces the box exactly. Usefit insideorfill and overflowto keep the aspect ratio. - Sizing against the wrong thing. Check
against:a sizeuses your typedwidth/height,the canvasandanother layerignore those fields entirely.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| layers | LAYERS | The stack holding the layer to scale. Wire in Add Layer, Layer Edit or anything else answering a LAYERS document. | |
| resize_mode | COMBO | How the layer reaches the box. `fit inside` keeps the whole layer visible with space left over; `fill and overflow` covers the box and runs past its edges; `stretch` takes the box exactly and distorts. | |
| against | COMBO | What the layer is fitted to. `the canvas` is the document's own size; `a size` is the width and height below; `another layer` is the box the layer target_index or target_name draws in. | |
| index | INT | -1-16384–16384 | Which layer is scaled, counting 0 from the back of the stack. -1 is the front layer. Ignored while layer_name names one. |
| layer_name | STRING | Name of the layer to scale instead of index. Blank uses index. 'sky' finds a layer called Sky, and finds Sky Backdrop where nothing is called exactly Sky. | |
| width | INT | 10241–16384 | Width of the box on `a size`, in pixels. 1024 fits the layer into a 1024-wide box. Ignored by the other two targets. |
| height | INT | 10241–16384 | Height of the box on `a size`, in pixels. 1024 fits the layer into a 1024-tall box. Ignored by the other two targets. |
| align | COMBO | middle center | Where the scaled layer sits inside the box. `middle center` centres it, `top left` puts its corner on the box's. |
| scale | FLOAT | 1.000.01–16 | Multiplies the fitted size afterwards. 1.0 = exactly the fit, 0.9 = a tenth smaller with a margin round it, 1.1 = a tenth larger. |
| target_index | INT | 0-16384–16384 | Which layer is fitted to on `another layer`, counting 0 from the back. 0 is the back layer, which is usually the plate. |
| target_name | STRING | Name of the layer to fit to instead of target_index. Blank uses target_index. Read only on `another layer`. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| layers | LAYERS | The stack with the layer scaled and placed, for Create Layered Image or another edit. |
| width | INT | The width the layer is now drawn at, in pixels. |
| height | INT | The height the layer is now drawn at, in pixels. |