Comfy Pencil Extract Layer
Pull one layer out of a ComfyPencil document — line art, a paint-over, or a mask
- document
- image
- mask
- layer_json
When you paint in Comfy Pencil Studio, you end up with a stack of layers - and sometimes you want just one of them, not the whole composite. ComfyPencilExtractLayer does exactly that: it pulls a single layer out of a PENCIL_DOCUMENT and hands you its color, its alpha, and its metadata as separate outputs.
The use cases are the reason you'd want this over just using the studio's composite image. Send line art to a ControlNet preprocessor without the color layers getting in the way. Take a paint-over layer and push it into its own img2img branch while the rest of the document stays put. Or grab the layer's alpha as a focused mask and feed it to an inpaint or detailing pass - since the mask output is just the layer's own transparency, it's often sharper and more intentional than anything a detector would generate. The pack's own docs list exactly these three, and they're the right ones.
Mechanically it's simple under the hood. The node resolves the document, then looks for a layer by layer_name first - a case-insensitive exact match, and it takes priority - and falls back to layer_index if the name isn't found. A layer_index of -1 (the default) grabs the top layer, which is the one you're usually painting on. Set an explicit index and you're counting stack order from the bottom, so 0 is the bottom-most layer. If nothing matches, it returns the last layer plus a layer_json that says "found": false, so you can tell it failed instead of silently getting the wrong layer.
Inputs: document, layer_name (string, empty by default), layer_index (-1 to 9999).
Outputs:
image- the layer's RGB, composited onto transparentmask- the layer's alpha channellayer_json- the layer's metadata as a JSON string: visibility, opacity, blend mode, id, and friends
That layer_json output is easy to ignore and worth a look when things confuse you. It's the pack's way of telling you exactly what that layer was - including whether the extraction actually found what you asked for.
Install is the same for every node in the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/criskb/Comfypencil ComfyPencil
Restart ComfyUI and hard-refresh the browser tab. No models to download, no API keys, no extra Python dependencies - it runs on ComfyUI's bundled torch and Pillow, targeting ComfyUI >= 0.16.0.
Two small gotchas. Layer names are matched case-insensitively but exactly, so if you have three layers all named "Sketch", the first match wins - name layers distinctly if you plan to extract by name. And remember that a layer's image output is just that layer, on transparent. If you expected the whole painting, you grabbed the wrong node; Render Document is the one that gives you the full composite.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| document | PENCIL_DOCUMENT | — | |
| layer_name | STRING | — | |
| layer_index | INT | -1-1–9999 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| layer_json | STRING | — |