Nodes/Comfypencil/Comfy Pencil Import Layer
ComfyUI Node

Comfy Pencil Import Layer

Comfy Pencil Import Layer

By criskb·Created 6 months ago·Updated 5 months ago· 1
Comfy Pencil Import Layer
  • document
  • image
  • mask
  • document
  • image
  • mask
  • metadata_json
layer_nameImported Layer
blend_modenormal
opacity1.00
visibletrue
placementtop
resize_modefit
persist_to_sourcetrue
flatten_backgroundfalse

Comfy Pencil Studio paints; this node feeds it. ComfyPencilImportLayer takes an image from anywhere else in the graph - a fresh generation, a ControlNet preprocess, an upscale, a reference photo - and injects it into a ComfyPencil document as a real layer with its own blend mode, opacity, and position in the stack. Then you open the studio and paint over it, or stack several imports into one layered file.

That's the pattern worth internalizing: generate a base, import it as a layer, hand-paint the fix, send the composite back through the sampler. It turns "paint in another app, import, hope" into a loop that stays entirely inside ComfyUI.

Mechanically it's a straightforward composite. The node takes the IMAGE (plus an optional MASK used as the layer's alpha), converts it to RGBA, resizes it to the document canvas according to resize_mode, and inserts it at the top or bottom of the stack. Then it re-renders the whole document and hands you the result. The persist_to_source toggle (on by default) saves the new layer back to the on-disk document when that document has a stable id, so the import is still there next time you open the studio - not just in the current run.

The inputs that matter:

  • blend_mode - normal, multiply, screen, overlay, soft-light, add. Multiply is the classic for dropping line art or a texture over a base.
  • resize_mode - this is the one beginners get surprised by. fit letterboxes onto the canvas (centered, with transparency around it), fill scales to cover and crops the overflow, stretch distorts to fill edge to edge, and center drops the image at its native size in the middle. fit is the safe default; fill is what you want when a generated image must cover the whole canvas.
  • placement - top or bottom of the layer stack.
  • opacity - 0.0 to 1.0.

Outputs are document (the updated PENCIL_DOCUMENT, which you can chain into Render Document or Extract Layer), image and mask (the freshly composited result), and metadata_json with the document summary.

Install is shared with the rest of the pack:

cd ComfyUI/custom_nodes
git clone https://github.com/criskb/Comfypencil ComfyPencil

Restart, hard-refresh the browser, and find it under Comfy Pencil. No models, no keys, no extra Python dependencies - it runs on ComfyUI's bundled torch/Pillow, and targets ComfyUI >= 0.16.0.

Two traps worth knowing. persist_to_source only does anything if the document already has a saved id - a fresh, never-saved doc has nowhere to write, so save or open a project in the studio first if you want the import to stick. And flatten_background only affects this node's image output; it doesn't change the stored layer data, so don't expect it to alter what the studio shows. If you're importing a mask-backed image, that's exactly what the optional mask input is for - wire it in and the mask becomes the layer's alpha instead of a solid rectangle.

Categorycomfypencil/document

Inputs (11)

NameTypeDefaultDescription
documentPENCIL_DOCUMENT
imageIMAGE
layer_nameSTRINGImported Layer
blend_modeCOMBOnormal6 options: normal, multiply, screen, overlay, soft-light, add
opacityFLOAT1.000–1
visibleBOOLEANtrue
placementCOMBOtop2 options: top, bottom
resize_modeCOMBOfit4 options: fit, fill, stretch, center
persist_to_sourceBOOLEANtrue
flatten_backgroundBOOLEANfalse
maskoptMASK

Outputs (4)

NameTypeDescription
documentPENCIL_DOCUMENT
imageIMAGE
maskMASK
metadata_jsonSTRING