PSD Replace
Swap a real Photoshop layer from inside ComfyUI
- image
- IMAGE
Here's the workflow that makes this node worth having: you generate a batch of images, and you want each one dropped into the same layer of a Photoshop file - a poster template, a phone mockup, a wallpaper frame - and exported flattened. Doing that by hand means opening Photoshop per image, right-clicking the smart object, replacing contents, exporting. Dozens of times. PSD Replace automates the whole loop inside your graph, and it's basically the only node that does.
It's a small, niche pack (one node, five stars, barely a whisper on Reddit), so set expectations: this isn't a polished suite, it's a focused utility. But if your job is "same template, many generated variants," it's the thing you'd reach for.
How it works
Here's the twist: Python is useless at writing real PSD files, so this node doesn't do the heavy lifting itself. The Python side base64-encodes your image, pipes a little JSON to a bundled Node.js script (index.js) via subprocess, and that script does the actual surgery using the ag-psd and canvas libraries. It loads the PSD, finds your layer by name (searching recursively through layer groups), swaps the image in - replacing the linked-file data for smart objects/placed layers, or the layer canvas for plain layers - then re-composites the whole document, blend modes, opacity, and clipping groups included. The result comes back as a PNG, which Python converts into a normal IMAGE tensor. The upshot: the output isn't a naive paste, it's a proper re-render of the file.
One consequence of that design: it's a Node app, not a Python one. If Node isn't installed and on your PATH, the node just fails.
The inputs that matter
- psd - a dropdown of
.psdfiles. It only looks inComfyUI/psd/(created automatically), so that's where your templates go. - layer_name - the exact name of the layer or smart object you're replacing. It must match the name in Photoshop, spelling included; if it can't find it, it errors out.
- image - the IMAGE tensor that becomes the new layer content. Note it takes the first image of a batch only, so one replacement per node call.
- save_psd (default off) - per the author's tooltip, whether to save the psd file. Leave it off unless you specifically want the edited file written back; normally you just get the flattened output.
The output is a single IMAGE - the flattened composite - which you wire straight into a Preview or Save Image node. There's an example workflow in the repo's assets/ folder that chains several of these off one LoadImage, which is exactly the batch-template pattern.
Installing it
ComfyUI Manager: search for PSD Replace. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/lgldlk/ComfyUI-PSD-Replace
cd ComfyUI-PSD-Replace
npm install
Then restart ComfyUI. No model downloads, no weights - the only "dependency" is Node.js (the author recommends 18+), and npm install fetching ag-psd plus canvas. That second one is the real install gotcha: canvas is a native module, so on Linux it compiles and needs build tools like g++, pkg-config, and the cairo dev packages, or npm install will throw. Windows and macOS usually grab prebuilt binaries and skip the pain. Also, as of this writing the GitHub repo returns 404 - deleted or renamed - so if Manager can't find it, grab the source from a mirror or fork while it's still around.
Common issues
- "node" isn't recognized / process fails - Node isn't installed or isn't on PATH. Install 18+, re-run
npm installin the pack folder, restart ComfyUI. - The psd dropdown is empty - your templates aren't in
ComfyUI/psd/. That folder is the only place it looks, subfolders included. - Layer not found error - the name in
layer_namedoesn't match what's in the file. Check for renames and group nesting. - Text layers come out in the wrong font - the Node script tries to register fonts from the OS font directory (e.g.
/usr/share/fontson Linux) and falls back to Arial/sans-serif when it can't. Test with a text-heavy template before trusting it. - Slow on big files - the whole document re-composites in memory in JavaScript, so a 10,000-layer monster will chug. Keep templates lean.
It's a quirky little bridge between the diffusion world and the design world, and Node.js being in the chain makes it fiddlier to install than a pure Python node. But for batch-swapping one smart object across a stack of PSD templates, it beats a weekend of clicking "Replace Contents" by a mile.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| psd | COMBO | 0 options: | |
| image | IMAGE | — | |
| layer_name | STRING | — | |
| save_psd | BOOLEAN | false | 是否保存psd文件 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |