ComfyUI Node

TextEncodeReferenceImages

One node that teaches Qwen-Image-Edit, Flux 2, and Z-Image to look at your reference image

By sebagallo·Created 8 months ago·Updated 6 months ago· 0
TextEncodeReferenceImages
  • clip
  • vae
  • image_encoder
  • images
  • CONDITIONING
prompt
vl_selectionnone
auto_resize_imagestrue

If you've ever opened an editing workflow for Qwen-Image-Edit, FLUX.2 Klein, or Z-Image and stared at a stack of nodes doing things like TextEncodeZImageOmni plus a VAE encode plus a conditioning-set-values, this node is the cleanup. It's a single conditioning category node that takes a prompt, your reference image(s), and - depending on which model you're driving - emits the conditioning those models actually want. One in, one out, and the fiddly vision-token plumbing happens inside.

The reason it exists: these models don't use reference images the way SD1.5-era IP-Adapter did. Kontext, Qwen-Image-Edit, and Flux 2 consume the image in-context - the picture is tokenized right into the text encoder's prompt along with your words. So "change the shirt to red" plus an image becomes one conditioning bundle, and identity is preserved structurally rather than through an adapter. That's the whole game, and this node automates it.

How it works

Under the hood it's a clip.tokenize(..., images=..., llama_template=...) call with a strategy picked by vl_selection:

  • qwen image edit - prepends a hardcoded Qwen-style system template ("Describe the key features of the input image… then explain how the user's text instruction should alter it") and appends Picture 1: <|vision_start|><|image_pad|><|vision_end|> markers per image. This is aimed squarely at Qwen-Image-Edit.
  • z-image base omni - the rebased logic from ComfyUI's own TextEncodeZImageOmni, the node people reach for with Z-Image and FLUX.2 Klein. It builds the <|vision_start|>/<|vision_end|> user-turn scaffolding and attaches reference_latents_text_embeds so the model knows images are coming.
  • none - plain text encoding. Which sounds useless until you realize the node still lets you attach the extras below.

On top of the in-context tokens, you can optionally wire an image_encoder (CLIP Vision) and/or a vae. Each image gets CLIP-Vision-encoded into clip_vision_outputs and/or VAE-encoded into reference_latents, both glued onto the same CONDITIONING output. So it's really three mechanisms in one node: text tokens, vision embeddings, and latent references.

Inputs that matter

  • vl_selection - the one you must not skip. This is the footgun: it defaults to none, and on none your images do nothing unless you've also wired image_encoder or vae. Set it for your model, or you'll silently get a plain text encode and wonder why nothing edits.
  • clip - the model's text encoder (Qwen's, FLUX.2's Qwen3-encoder, Z-Image's Qwen3-4B…). Must be the one the checkpoint expects.
  • images - reference image(s). Batch support is native: combine several with ComfyUI's Batch Images node and they're all handled.
  • vae / image_encoder - optional. vae enables the reference_latents path; image_encoder enables CLIP-Vision embeddings.
  • auto_resize_images (default on) - scales images to ~1MP before VAE encoding, rounding to multiples of 8. Handy, but note it only touches the VAE-latent path; the CLIP-Vision encode runs at native resolution.

The single CONDITIONING output wires straight into a sampler's conditioning input.

Installing

It's on the Comfy registry, so the easy route is ComfyUI Manager → search "Text Encode Reference Images" → install. Or by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/sebagallo/comfyui-sg-text-encode-reference-images

Then restart ComfyUI. That's it - pyproject.toml declares zero Python dependencies and there's no requirements.txt. All model files are the ones you already have for the base models.

Gotchas

  • It needs a current ComfyUI. The code imports from comfy_api.latest and uses the newer extension entrypoint API. On an old build it won't import; update ComfyUI first if the node shows an error at startup.
  • The templates are hardcoded to Qwen-style and Z-Image-style tokenizers. Don't expect this on a plain SDXL/Flux.1 CLIP - it's built for the VL generation models, and the README says so.
  • Resize vs. quality is a real tradeoff. The community noted the 1MP auto-resize on the Z-Image Omni approach is faster but loses fine detail on big references; if a high-res source matters for your edit, turn auto_resize_images off and pre-resize yourself.

For identity-critical edits, Qwen-Image-Edit and Flux 2 Dev are the consensus picks (Klein drifts more on faces); this node just gets whichever you chose wired up in about six nodes less.

Categoryconditioning

Inputs (7)

NameTypeDefaultDescription
clipCLIPThe CLIP model to use for encoding.
promptSTRINGThe text prompt to encode.
vl_selectionCOMBOnoneSelect the Vision-Language model strategy.
auto_resize_imagesBOOLEANtrueAutomatically resize reference images to 1024x1024.
vaeoptVAEVAE for encoding reference images into latents.
image_encoderoptCLIP_VISIONCLIP Vision model for encoding reference images.
imagesoptIMAGEReference images to be used for conditioning (supports image batches).

Outputs (1)

NameTypeDescription
CONDITIONINGCONDITIONING