ComfyUI Node

StringPicker

Steal a string out of a PNG's embedded workflow

By morino-kumasan·Created 2 years ago·Updated a day ago· 1
StringPicker
  • image
  • STRING
target_title
image_index0
string_index0

Here's a genuinely clever node, and one almost nobody will guess the purpose of from the name. StringPicker takes an IMAGE that came from LoadImage, opens the PNG file on disk, reads the ComfyUI workflow embedded in it, finds a node by its title, and hands you one of that node's widget values as a STRING.

You know that trick where you drag a generated image back into ComfyUI and the whole graph comes back? This node does the same thing programmatically. Point it at a previous run's output and it can pull a prompt - or a settings summary - straight out of the file, with no copy-pasting.

The author's own hiresfix2.sample.json is the canonical use: stage two loads stage one's PNG, and StringPicker (target title Summary) reads stage one's settings summary out of the embedded workflow and feeds it into SummaryReader, which unpacks it into prompts, LoRA list and seed. Stage two configures itself from stage one's file.

How it works

The code does, in order:

  1. Looks up its own node in the live workflow to find which node feeds its IMAGE input.
  2. Reads widgets_values[image_index] off that upstream node - for a stock LoadImage, index 0 is the filename.
  3. Opens that file from ComfyUI's input directory with PIL and parses img.info["workflow"] - the workflow chunk ComfyUI writes into every saved PNG.
  4. Finds the first node in that embedded workflow whose title equals target_title, and returns widgets_values[string_index].

So image_index is "which widget on the loader node holds the filename" and string_index is "which widget on the titled node holds the string I want" - usually 0 for a text node. Both are plain INTs with a default of 0.

Inputs and outputs

image (IMAGE, forceInput - the tooltip says "from LoadImage."), target_title (STRING), image_index (INT, default 0), string_index (INT, default 0). One STRING output.

Install

Manager search for the pack, or:

cd ComfyUI/custom_nodes
git clone https://github.com/morino-kumasan/comfyui-toml-prompt

restart ComfyUI. Nothing to pip install - requirements.txt is empty and PIL comes with ComfyUI. The README's install block is stale; use the HTTPS clone above.

Where people get burned

The PNG has to carry a workflow chunk. Images saved by ComfyUI's own SaveImage do. Images generated through an API-only path store just the flattened prompt chunk, and the node's img.info["workflow"] lookup raises a KeyError. Any tool that re-encodes the PNG - a quick resize, a metadata stripper, most "optimise my images" utilities - drops the chunks entirely.

The title has to exist, exactly. The node does [node for node in ... if node.get("title","") == target_title][0] - no match means indexing an empty list, i.e. an IndexError. Titles are set by double-clicking a node's header in the UI, so this is a genuinely manual contract: title the node Summary, and name Summary here.

Widget indices are positional and brittle. image_index assumes a loader whose filename is the first widget, string_index assumes your target node's text is its first widget. Swap the loader for a different one, or target a node with a dropdown before its text box, and you're reading the wrong thing - silently, into a text input that will happily render gibberish.

Read-only, one shot. The node only ever reads the file. It doesn't load the workflow, doesn't change your graph, and won't help you recover a lost seed unless something in that PNG already stored it.

Categoryutils

Inputs (4)

NameTypeDefaultDescription
imageIMAGEfrom LoadImage.
target_titleSTRING
image_indexINT0filename index of widgets_values.
string_indexINT0string index of widgets_values.

Outputs (1)

NameTypeDescription
STRINGSTRINGSTRING not disabled.