ComfyUI Node

Img2Img

One node for txt2img and img2img — and it hands you the filename too

By loz2754·Created 8 months ago·Updated about 24 hours ago· 5
Img2Img
  • vae
  • empty_latent
  • boolean
  • IMAGE
  • MASK
  • latent
  • filename
  • cleaned filename
  • width
  • height
  • denoise strength
img2imgfalse
denoise_strength1.00
new_width1024
new_height1024
latent_width
latent_height
image
max_num_words0

If you've rebuilt the txt2img → img2img switch more times than you can count - toggle the image loader, swap in a resize, remember which denoise goes where - AUNImg2Img exists to retire that subgraph. It's the whole "load a reference, resize it, encode it to latent" routine in a single node, with a boolean that flips between full txt2img and img2img modes without you rewiring anything. It's part of the AUN pack's all-in-one philosophy: fewer nodes, cleaner graphs, filenames that actually flow downstream.

How it works

The mechanism is the same dance every img2img workflow does, just packaged. Flip img2img on and the node opens your image, resizes it so the longest side matches your new_width / new_height (aspect ratio preserved, Lanczos resampling), then encodes it to latent space with the VAE you feed in. That latent is what your KSampler denoises. Flip it off and it ignores the image entirely, passes your empty_latent straight through, and pins denoise to 1.0 - a clean txt2img start.

A couple of details worth knowing before you wire it up:

  • latent_width and latent_height are connections, not widgets. They come from your Empty Latent node so the node always knows what resolution the sampler expects.
  • It returns the actual width / height it computed after resizing, and the denoise strength it used. Wire those into your KSampler (or a text node) and the filename and the sampling stay in sync automatically.

Inputs and outputs that matter

For a beginner the inputs to actually touch: img2img (the mode toggle), image (the reference you upload), denoise_strength, new_width/new_height, and vae + empty_latent which you wire in from a VAE Loader and Empty Latent.

Outputs, in the order you'll use them:

  • latent - goes to your KSampler's latent input. This is the point of the node.
  • IMAGE and MASK - the loaded/resized image and its alpha as a mask (all ones if the image has no alpha).
  • boolean - mirrors the img2img flag, handy for driving a switch elsewhere.
  • filename and cleaned filename - the source filename, optionally word-capped by max_num_words. The cleaned version is the one you want in prompts or save paths.

Installing it

AUN is one pack with all of these nodes, so you install it once:

  • ComfyUI Manager (recommended): search for "AUN ComfyUI Nodes" and install, then restart ComfyUI.
  • Manual: from your ComfyUI folder, cd custom_nodes && git clone https://github.com/loz2754/AUN-ComfyUI-Nodes, then restart.

The pack's requirements.txt pulls in piexif, opencv-python-headless, imageio-ffmpeg, and requests. Manager handles these automatically; if you cloned by hand and hit ModuleNotFoundError: cv2 or piexif, run pip install -r custom_nodes/AUN-ComfyUI-Nodes/requirements.txt.

Common issues

The one I keep seeing: people expect new_width/new_height to be used in txt2img mode too. They're not - that's what empty_latent is for. If you flip the mode and your image comes back huge or tiny, check that your Empty Latent is set where you want the final canvas, because in img2img mode the node resizes to your new_ values, not to the latent. And remember img2img only preserves general layout, not your exact subject - same as every non-ControlNet img2img, just faster to set up here.

CategoryAUN Nodes/Image

Inputs (10)

NameTypeDefaultDescription
img2imgBOOLEANfalseEnable/disable Img2Img mode.
denoise_strengthFLOAT1.000–1Set the denoise strength for Img2Img.
new_widthINT10240–2048Set the new width for the image when Img2Img is enabled. The longest side of the image will be resized to this length. Aspect ratio is preserved.
new_heightINT10240–2048Set the new height for the image when Img2Img is enabled. The longest side of the image will be resized to this length. Aspect ratio is preserved.
latent_widthINTThe width of the latent space (from EmptyLatentImage node). The longest side of the image will be resized to this length. Aspect ratio is preserved.
latent_heightINTThe height of the latent space (from EmptyLatentImage node). The longest side of the image will be resized to this length. Aspect ratio is preserved.
imageCOMBOSelect the image to use for Img2Img.
max_num_wordsINT00–32Maximum number of words to keep for both filename outputs. Set to 0 for no limit.
vaeVAEThe VAE to use for encoding the image to latent space.
empty_latentLATENTThe empty latent image to use when Img2Img is disabled.

Outputs (9)

NameTypeDescription
booleanBOOLEAN
IMAGEIMAGE
MASKMASK
latentLATENT
filenameSTRING
cleaned filenameSTRING
widthINT
heightINT
denoise strengthFLOAT