Nodes/TrentNodes/PSD Layer Flatten
ComfyUI Node

PSD Layer Flatten

Merging a Stack of PSD Layers Into One Image — With the Pack's Mask Convention

By TrentHunter82·Created 9 months ago·Updated 4 days ago· 36
PSD Layer Flatten
    • image
    • mask
    folder_path
    start_index0
    end_index0
    background_colortransparent
    respect_visibilitytrue

    Sometimes you don't want layers at all - you want one flat image. This node takes a contiguous range of PSD layers from a splitter folder and rasterizes them together into a single composite, reading each layer's position and opacity from the manifest. The canonical use: merging a multi-layer background into one image so you can feed it into a background-removal model or an inpainting pass as a single unit.

    What it does

    folder_path points at the splitter output; start_index and end_index (both inclusive, 0 = bottom) select the contiguous range to merge - the tooltips explicitly suggest wiring these from PSDBackgroundDetect's bg_start / bg_end. background_color sets the canvas backdrop (transparent / white / black / hex), and respect_visibility (default on) skips layers the PSD marks hidden.

    Outputs are the flat image and a mask - and this is where you have to pay attention. The mask here uses the pack's inverted convention: white = transparent, black = opaque. That matches the alpha-as-PS-sees-it way this pack's splitter and loader output masks. It's correct, and it's the opposite of what ComfyUI's own mask nodes expect.

    The honest naming problem

    There are two flatten nodes in this pack - this one and PSD Layer Flatten (RGBA) - and their names suggest the difference is alpha handling, but the actual difference is the mask polarity. The image outputs are effectively the same RGBA composite; what changes is which mask convention you get. If you're feeding the mask into a standard ComfyUI node that assumes white = opaque, you want the RGBA variant, which outputs standard masks. If you're keeping everything inside this pack's convention (feeding the mask back to pack nodes), this one is consistent with the rest of the family.

    That makes this the right node when you're staying within the pack's own toolchain, and the RGBA variant the right one when your mask is heading into generic ComfyUI territory.

    Installing it

    Part of TrentNodes; install once:

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

    ComfyUI Manager ("Trent Nodes") also works - with the recurring caveat that the author's day-one repo rename left a duplicate registry entry, so Manager occasionally flags the pack as "unsafe" and the manual clone is the reliable path. No models, no downloads; it reads the splitter's PNGs and manifest.

    Where it trips people up

    • Inverted mask surprise - the mask output is white = transparent. First time, people flip it and wonder why their cutout is inverted. Flip it before wiring into standard nodes.
    • Index drift - any change to how you split (different layer_types filters) shifts indices; re-split and re-run the chain.
    • Hidden layers - with respect_visibility on, hidden layers vanish from the composite. That's usually what you want; it's a surprise only if you forget it exists.
    CategoryTrent/PSD

    Inputs (5)

    NameTypeDefaultDescription
    folder_pathSTRINGFolder from PSDLayerSplitter (must contain _manifest.json)
    start_indexINT00–9999First layer index to include (0 = bottom). Wire from PSDBackgroundDetect bg_start.
    end_indexINT00–9999Last layer index to include (inclusive). Wire from PSDBackgroundDetect bg_end.
    background_colorSTRINGtransparentCanvas backdrop: 'transparent', 'white', 'black', or hex like '#FFFFFF'
    respect_visibilityBOOLEANtrueIf True, skip layers marked hidden in the original PSD

    Outputs (2)

    NameTypeDescription
    imageIMAGEFlattened RGBA composite of the selected layers
    maskMASKAlpha mask of the flattened result (inverted: white = transparent)