VAEEncodeAdvanced
Encode with resizing and masks built in
- image_1
- image_2
- mask
- latent
- vae
- latent_1
- latent_2
- mask
- empty_latent
- width
- height
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 proportionandpadavoid distortion;stretchwill squash the aspect ratio, so use it deliberately. - latent_type (
4_channels/16_channels, default16_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.
Inputs (13)
| Name | Type | Default | Description |
|---|---|---|---|
| resize_to_input | COMBO | false | 5 options: false, image_1, image_2, mask, latent |
| width | INT | 10240–16384 | — |
| height | INT | 10240–16384 | — |
| mask_channel | COMBO | 4 options: red, green, blue, alpha | |
| invert_mask | BOOLEAN | false | — |
| latent_type | COMBO | 16_channels | 2 options: 4_channels, 16_channels |
| interpolation | COMBO | lanczos | 6 options: nearest, bilinear, bicubic, area, nearest-exact, lanczos |
| method | COMBO | fill / crop | 4 options: stretch, keep proportion, fill / crop, pad |
| image_1opt | IMAGE | — | |
| image_2opt | IMAGE | — | |
| maskopt | IMAGE | — | |
| latentopt | LATENT | — | |
| vaeopt | VAE | — |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| latent_1 | LATENT | — |
| latent_2 | LATENT | — |
| mask | MASK | — |
| empty_latent | LATENT | — |
| width | INT | — |
| height | INT | — |