Nodes/ComfyUI-XJNodes/Load Image With Metadata
ComfyUI Node

Load Image With Metadata

Load an image and get its whole biography back as data

By alexjx·Created 10 months ago·Updated 4 months ago· 0
Load Image With Metadata
    • image
    • file_path
    • file_name
    • width
    • height
    • format
    • metadata
    directory
    subdirectory
    image

    Most of the time you just want pixels, and ComfyUI's built-in Load Image is fine. But sometimes you need the pixels and everything that was written next to them: the exact file path, the dimensions, the format, and the whole JSON blob of PNG text chunks - including the workflow that generated the image in the first place. That's the slot XJLoadImageWithMetadata fills.

    It's from the ComfyUI-XJNodes pack, and it's designed as the natural partner to the same pack's Save Image With Metadata node. Save with metadata, come back days later, reload it, and the node hands you the metadata back as plain strings you can parse, display, or feed into a JSON Extractor. It reads from both input and output directories, which the stock loader can't really do cleanly.

    How it works

    The load path is ComfyUI's standard PIL-based loader: open the file, strip EXIF rotation, convert frames to RGB tensors, and handle multi-frame formats (like animated webp or multi-page tiff) as a batch. What separates this from the stock node is the metadata layer. For PNGs, the format stores key/value text chunks (tEXt), and the node scoops up all of them - prompt, workflow, and anything custom like the xj_metadata key this pack's saver writes - and returns them as one JSON string. For JPEG it reads what EXIF gives you.

    Two design details matter for real use:

    • The image dropdown is populated by a browser UI (the pack ships a bit of frontend JS), so it lists the actual files in the directory you selected - no typing paths.
    • IS_CHANGED hashes the file's contents, not just its name. If the file changes on disk, ComfyUI reruns the node. If you edit a PNG in an external editor and re-run, you get fresh metadata instead of a cached stale blob.

    The inputs and outputs

    Inputs are the three you'd expect:

    • directory - input or output, which root folder to look in.
    • subdirectory - an optional subfolder inside that root (leave blank for the root itself).
    • image - the file to load, picked from the populated dropdown.

    The outputs are where it earns its name:

    • image (IMAGE) - the pixels, ready for anything.
    • file_path (STRING) and file_name (STRING) - the full path and basename, handy for downstream logic.
    • width and height (INT) - dimensions of the first frame.
    • format (STRING) - e.g. PNG, JPEG, WEBP.
    • metadata (STRING) - the JSON of all PNG text chunks (or {} if there are none).

    That metadata output is the gold. Feed it into a JSON parser, pull out the original prompt, and you've got a crude but effective image-to-prompt round-trip.

    Installing it

    This node lives in ComfyUI-XJNodes - one install, whole pack:

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

    then restart ComfyUI (or install via ComfyUI Manager by searching ComfyUI-XJNodes). Zero model downloads, empty requirements.txt - it only needs what ComfyUI already ships.

    Common issues

    The classic gotcha is format behavior: if you save a JPEG, you don't get PNG text chunks, so metadata comes back thin or empty. Metadata round-tripping really wants PNG (or the pack's own WebP EXIF handling). Also worth knowing this is a personal-project pack with no real community around it - if the browser UI ever fails to list files, check that your subdirectory matches exactly, since the node joins it onto the input/output root and an empty dropdown usually means a path mismatch.

    CategoryXJNodes/image

    Inputs (3)

    NameTypeDefaultDescription
    directoryCOMBO2 options: input, output
    subdirectorySTRING
    imageCOMBO1 options:

    Outputs (7)

    NameTypeDescription
    imageIMAGE
    file_pathSTRING
    file_nameSTRING
    widthINT
    heightINT
    formatSTRING
    metadataSTRING