Nodes/TrentNodes/PSD Layer Save As PSD
ComfyUI Node

PSD Layer Save As PSD

Swap One Layer's Artwork and Keep the Rest of the PSD Intact

By TrentHunter82·Created 9 months ago·Updated 4 days ago· 36
PSD Layer Save As PSD
  • replacement_image
  • output_path
  • preview
original_psd_path
target_layer_name
output_psd_path
resize_modestretch

The genuinely impressive trick in this pack: take an existing .psd, replace one layer's pixels with an image you generated, and write out a new PSD where every other layer - text, smart objects, adjustment layers, masks, blend modes, group structure - is exactly as it was. The original file is never touched. If your pipeline is "AI art goes into a client's design file," this is the node that makes it a drop-in replacement instead of a rebuild.

How it works

It opens the original PSD with psd-tools, finds the target layer by name (walking recursively into groups, first match wins), rasterizes that one layer's replacement, and writes a new file. Everything else is preserved structurally - which is the part that's actually hard, because a naive "flatten and re-save" destroys editable text and layer effects. The replaced layer becomes a raster PixelLayer; its siblings keep their identity. The code even handles non-Latin layer names through the proper Unicode tagged block, so Chinese, Korean, or accented names survive.

The inputs that matter

  • original_psd_path - the source; read-only, never modified.
  • replacement_image - your new pixels for that layer.
  • target_layer_name - the layer to replace, by name. This is where PSD Layer Names earns its keep: use its name_at_index output so you match an actual name instead of guessing.
  • output_psd_path - where the new file goes (parent dirs are auto-created). Because the original is never overwritten, you always have a copy to go back to.
  • resize_mode - how to fit your replacement into the original layer's bounds: stretch (default), fit (keep aspect, letterbox), cover (keep aspect, crop), center, or native (keep the replacement's own size, placed at the original layer's top-left).

Outputs are output_path (the absolute path written) and preview (a composite preview of the modified document, so you can eyeball the result before opening it in Photoshop).

Installing it

Part of TrentNodes; one pack, one install:

cd ComfyUI/custom_nodes
git clone https://github.com/TrentHunter82/TrentNodes.git
cd TrentNodes
pip install -r requirements.txt

ComfyUI Manager ("Trent Nodes") works too, modulo the known quirk that the author's day-one repo rename left a duplicate registry entry and Manager sometimes flags the pack as "unsafe" - the clone is the dependable route. psd-tools is the real dependency here and it's in requirements.txt.

Where people get burned

  • Empty target_layer_name - nothing matches, so nothing gets replaced (the node needs a name; it won't guess by index).
  • Wrong layer replaced - matching is by name, first match wins. If the PSD has two layers named the same, the bottom one gets replaced. Rename one layer in the source, or use PSD Layer Names to be sure of what you're targeting.
  • Expecting the original to survive - it does, by design. The output path is a new file. If your downstream step references the original path, wire output_path through instead.
CategoryTrent/PSD

Inputs (5)

NameTypeDefaultDescription
original_psd_pathSTRINGSource .psd to read structure from. Not modified.
replacement_imageIMAGENew pixels for the target layer
target_layer_nameSTRINGName of the layer to replace (matches PSD layer names; walks into groups). First match wins.
output_psd_pathSTRINGDestination .psd path. Parent directory is created if missing.
resize_modeCOMBOstretchHow to fit the replacement into the original layer's bounding box. 'native' keeps the replacement's own size (positioned at the original layer's top-left).

Outputs (2)

NameTypeDescription
output_pathSTRINGAbsolute path of the written .psd file
previewIMAGEComposite preview of the modified PSD