ComfyUI Node

Assoc Img

Stick an image inside a dict as a base64 data URI

By wmatson·Created 3 years ago·Updated about a year ago· 18
Assoc Img
  • dict
  • value
  • dict
key
formatwebp
quality92

Assoc Img is the clever one in the pack's dict family. Where Assoc Str adds a plain string, this node takes an actual IMAGE from your graph, encodes it, and stores it in a dict as a base64 data URI - a string that starts with data:image/webp;base64,. The payoff: you can attach a rendered image to a JSON payload and POST it somewhere without ever touching the filesystem.

Why you'd reach for it

The natural end of this pack's chain is HTTP POST: build a dict, send it as JSON. The problem is that a raw image tensor can't ride along in JSON. Assoc Img solves that by inlining the image into the dict as a data URI, so a single POST can carry both metadata and the actual picture - great for "generated image + prompt + seed" notifications to your own API, or feeding an image into a multimodal webhook without standing up object storage.

How it works

Under the hood it converts the first frame of the image tensor to a PIL image, saves it into memory with the format you pick (webp by default), base64-encodes the bytes, and prefixes the data:image/<format>;base64, header. The result is stored as a plain string value under your key. Two knobs, both optional:

  • format (STRING, default webp) - the encoding. WebP is the sensible default: small and universally supported in modern browsers/APIs. png and jpg work too.
  • quality (INT, default 92) - the compression quality for lossy formats. Lower it to shrink the payload, at the cost of visible artifacts.

The inputs that matter

  • dict (DICT) - the map you're adding to. Start from Empty Dict or an existing chain.
  • key (STRING) - the field name.
  • value (IMAGE) - the image to encode. Take it straight off a Load Image or VAE Decode.
  • dict (DICT, output) - the updated map, now with a hefty data-URI string inside.

Installing it

Part of easy-comfy-nodes. ComfyUI Manager: search easy-comfy-nodes. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/wmatson/easy-comfy-nodes
# restart ComfyUI

Where people get burned

  • Only the first frame is encoded. The code grabs value[0], so a batch of images becomes just the first one. Encode per-image if you need them all.
  • Payload size blows up fast. A data URI is roughly 33% larger than the raw file, and a big PNG at quality 92 can be megabytes of text. WebP at a lower quality keeps things sane. For genuinely large results, upload to S3 instead and send the URL - which is exactly what this pack's S3 node is for.
  • The format string is passed straight to PIL. A typo like jpeg when you meant jpg - actually PIL handles both - but an unsupported format will just error. Stick to webp/png/jpg.

It's the node that turns "send structured data" into "send structured data with a picture attached." For automation people, that's a genuinely useful trick.

CategoryDICT

Inputs (5)

NameTypeDefaultDescription
dictDICT
keySTRING
valueIMAGE
formatoptSTRINGwebp
qualityoptINT92

Outputs (1)

NameTypeDescription
dictDICT