Nodes/RES4LYF/VAEEncodeAdvanced
ComfyUI Node Runs on cloud

VAEEncodeAdvanced

Encode with resizing and masks built in

By ClownsharkBatwing·Created 2 years ago·Updated 18 days ago· 1,222
VAEEncodeAdvanced
  • image_1
  • image_2
  • mask
  • latent
  • vae
  • latent_1
  • latent_2
  • mask
  • empty_latent
  • width
  • height
resize_to_inputfalse
width1024
height1024
mask_channel
invert_maskfalse
latent_type16_channels
interpolationlanczos
methodfill / crop

The stock VAE Encode does one thing: image in, latent out, at whatever size the image already is. VAEEncodeAdvanced is the version that also handles the fiddly stuff you'd otherwise need three more nodes for - resizing to a target, choosing how to fit non-matching aspect ratios, pulling a mask out of a channel, and encoding two images plus a mask in a single pass. It's the Swiss-army encode for img2img, inpainting, and unsampling setups, which is exactly the kind of work RES4LYF is built for.

The reason it matters on flow-matching models: those use a 16-channel latent, and getting your encode to match the model's expected latent format and resolution is a step people quietly get wrong. This node makes the latent type and the resize explicit rather than leaving them to chance.

How it works

You feed it one or two images (and optionally a mask), tell it what size you want and how to fit the image to that size, and it encodes to a latent. The resize_to_input and method settings decide the geometry before the VAE ever runs, so the latent comes out at the resolution your sampler wants without a separate resize node in front.

The inputs and outputs that matter

The handful worth setting:

  • image_1 (optional IMAGE) - the main image to encode. image_2 and mask are there for dual-image and masked workflows.
  • width / height (INT, default 1024) - the target size to encode at.
  • method (stretch / keep proportion / fill / crop / pad) - how the image is fitted to that size. fill / crop (the default) covers the frame and trims overflow; keep proportion and pad avoid distortion; stretch will squash the aspect ratio, so use it deliberately.
  • latent_type (4_channels / 16_channels, default 16_channels) - match this to your model. Flux, SD3.5, and the other flow-matching models are 16-channel; older SD 1.5/SDXL latents are 4-channel. Get this wrong and the sampler receives a latent it can't read.
  • interpolation (default lanczos) - the resampling filter; lanczos is a good sharp default.
  • vae (optional VAE) - the VAE to encode with.

Outputs give you latent_1 and latent_2 (the encoded images), a passed-through mask, an empty_latent at the target size, and the resolved width / height as integers you can reuse downstream.

Installing it

ComfyUI Manager: search RES4LYF, install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/ClownsharkBatwing/RES4LYF/
cd RES4LYF
pip install -r requirements.txt

pip install in your venv or portable Python, restart, hard-refresh (F5). No downloads, but you supply your own VAE.

Where people get tripped up

The single biggest one is latent_type. If you're on Flux or SD3.5 and leave it - or set it - to 4_channels, or run an SDXL workflow at 16_channels, the encode "succeeds" but the sampler gets a mismatched latent and you get noise or an error. Match the channel count to the model family every time.

After that it's aspect ratios: if your source isn't the same shape as your width/height, the method decides whether you crop, pad, or distort. Reaching for stretch by accident is how faces come out subtly squashed. Pick keep proportion or pad when you care about the geometry, and fill / crop when you'd rather lose the edges than warp the subject.

CategoryRES4LYF/vae

Inputs (13)

NameTypeDefaultDescription
resize_to_inputCOMBOfalse5 options: false, image_1, image_2, mask, latent
widthINT10240–16384
heightINT10240–16384
mask_channelCOMBO4 options: red, green, blue, alpha
invert_maskBOOLEANfalse
latent_typeCOMBO16_channels2 options: 4_channels, 16_channels
interpolationCOMBOlanczos6 options: nearest, bilinear, bicubic, area, nearest-exact, lanczos
methodCOMBOfill / crop4 options: stretch, keep proportion, fill / crop, pad
image_1optIMAGE
image_2optIMAGE
maskoptIMAGE
latentoptLATENT
vaeoptVAE

Outputs (6)

NameTypeDescription
latent_1LATENT
latent_2LATENT
maskMASK
empty_latentLATENT
widthINT
heightINT