Nodes/ComfyUI-My-Nodes/写入PNG元数据
ComfyUI Node

写入PNG元数据

The name is a lie — it writes JSON files, not PNG metadata

By Tagbliton·Created 2 years ago·Updated about a year ago· 11
写入PNG元数据
      path./user/default/workflows
      namename
      json_data

      Let's get the honest truth out first: "Write Png Info" does not write PNG metadata. At all. There's no image input on this node - it takes a path, a name, and a JSON string, and writes a text file to disk. That's the entire job, and the name is doing some heavy advertising.

      The confusion is understandable, because the same pack ships a "读取PNG元数据" (Read Png Info) node that does read real PNG text chunks - the parameters and workflow that ComfyUI's SaveImage embeds. So you'd reasonably assume Write is the matching other half of that round trip. It isn't. The source is unambiguous: open(f"{path}/{name}{int(time.time())}.json", "w") writes your json_data string to a file. The name field isn't even a full filename - the current Unix timestamp gets appended, so a name of "caption" produces something like caption1764930000.json. There's no .png anywhere in the code path.

      This matters because of how ComfyUI's metadata convention actually works. The node graph and prompt live in PNG text chunks, and SaveImage is what embeds them - that's the file you drag back onto the canvas to rebuild a workflow. If that's the behavior you want, use SaveImage, not this node. What this node is good for is dumping JSON sidecars: a caption, an API response, extra parameters you want stored alongside your outputs. In the pack's DashScope-flavored world, the obvious move is piping an AI assistant node's JSON output in and stashing it to disk.

      Inputs, all required: path (STRING, default ./user/default/workflows, tooltip "保存路径" = save path), name (STRING, default "name" - the filename prefix), and json_data (multiline STRING). It's an output node with no return values, so it terminates a branch of your graph.

      Where people get burned: the default path is relative, resolved from wherever you launched ComfyUI - run it from a different working directory and the file lands somewhere you'll never find. Use an absolute path. Worse, the code swallows every error (except: pass), so a nonexistent directory silently does nothing. No error, no file, no clue. And don't forget the timestamp: the same name twice gives you two files, not an overwrite.

      Install is the pack's shared story - ComfyUI Manager and search "ComfyUI-My-Nodes", or:

      cd ComfyUI/custom_nodes
      git clone https://github.com/Tagbliton/ComfyUI-My-Nodes
      

      then restart. The heavy dependencies (dashscope, openai, soundfile, the urllib3==1.26.20 pin) are for the AI nodes; this one needs nothing beyond ComfyUI core. Just remember you're getting a JSON-file writer wearing a PNG jacket.

      Category我的节点/PngInfo

      Inputs (3)

      NameTypeDefaultDescription
      pathSTRING./user/default/workflows保存路径
      nameSTRINGname
      json_dataSTRING

      Outputs (0)

      No outputs