Nodes/ComfyUI-XJNodes/Load Image By Path
ComfyUI Node

Load Image By Path

Load an image by exact path, because 'dynamic' beats 'convenient'

By alexjx·Created 10 months ago·Updated 4 months ago· 0
Load Image By Path
    • IMAGE
    • MASK
    directory
    filename

    ComfyUI's built-in Load Image is a dropdown: it lists files from your input folder and you pick one. That's great until the file you want is computed, not chosen. Load Image By Path trades the convenience for the capability - instead of a dropdown, it takes two string inputs, directory and filename, and loads whatever they point at. The README's framing is the whole pitch: "useful for dynamic loading based on workflow logic (e.g. loading image path from metadata)."

    That's the killer use. You've extracted a filename from an image's embedded workflow metadata - the XJNodes JSON Extractor is built for exactly this - and now you want to load the image that metadata describes. With the stock loader you'd hit a wall: it can't take a filename from a wire. With this node, the filename flows in as a string from anywhere, and the loader just opens it. It's the difference between a graph that asks you questions and a graph that knows.

    How it works

    It joins directory and filename into a full path, verifies the file exists, opens it, and returns the image. Mechanically it's nearly the same as ComfyUI's core Load Image: EXIF orientation is honored, the image is converted to RGB and normalized to a 0..1 float tensor with a batch dimension. If the file has an alpha channel, that alpha comes out as a MASK output (inverted so that opaque = 0, the standard ComfyUI masking convention). No alpha means you get an empty 64×64 mask, same as core ComfyUI.

    What it deliberately skips: there's no preview thumbnail, no file browser, no dropdown of candidates. The path is entirely up to you and whatever produces it.

    Inputs and outputs

    • directory - a string path to the folder. Absolute paths work; there's no restriction to ComfyUI's input directory, which is the point
    • filename - the file name (or relative subpath) to load

    Outputs are IMAGE and MASK, both plain (single-image, not list). Wire IMAGE into a sampler or VAE, wire MASK into any mask-consuming node.

    Installing it

    Standard XJNodes install. ComfyUI Manager → search "ComfyUI-XJNodes" → install → restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/alexjx/ComfyUI-XJNodes
    # restart ComfyUI
    

    No extra dependencies - it's Pillow + numpy + torch, all already present. Look under XJNodes/image.

    Where it bites

    The node throws a FileNotFoundError if the path doesn't resolve, and a graph run will stop on that - there's no graceful fallback. So if you're building a dynamic pipeline, make sure the path-producing part upstream can't hand back garbage. Related: because there's no directory dropdown, paths in shared workflows are absolute to someone's machine, which is exactly why most loaders restrict you to the input folder. Use this node for your own automation, and swap in a dropdown loader before you share a workflow with a friend. And remember the directory input wants a path, not ComfyUI's magic "input" alias - if you want the input folder specifically, that's the pack's Load Images From Dir List, or just write the absolute path.

    CategoryXJNodes/image

    Inputs (2)

    NameTypeDefaultDescription
    directorySTRING
    filenameSTRING

    Outputs (2)

    NameTypeDescription
    IMAGEIMAGE
    MASKMASK