APNext Latent Generator
An empty-latent node that does the resolution math for you
- LATENT
- width
- height
This is a smarter replacement for ComfyUI's stock Empty Latent Image node. Instead of making you type exact pixel dimensions and hope they're a resolution your model likes, you tell it a target megapixel count and an aspect ratio, and it works out the width and height for you. Output a 16:9 image at roughly one megapixel without doing the arithmetic in your head. That's the whole pitch, and if you flip between aspect ratios a lot it's a genuine quality-of-life win.
It's the empty starting canvas every text-to-image workflow needs - the thing your sampler denoises into an image. This one just sizes that canvas intelligently.
How it works
You give it megapixel_scale (a target in megapixels, 0.1 to 2.0) and an aspect_ratio, and it computes dimensions that hit that pixel budget at that shape, snapped to multiples of 8 so the VAE is happy. Set width and height to a real value and it uses those directly; the auto-calculation is what you get when you lean on the megapixel/aspect controls instead. is_portrait flips the orientation so 16:9 becomes 9:16. It produces an empty (zeroed) latent tensor - no noise, no image yet - exactly like the stock node, just sized for you.
Why megapixels instead of raw pixels? Because different model families have different native resolutions - SDXL likes about 1MP, and going too far past a model's training resolution is where you get duplicated heads and stretched bodies. Thinking in megapixels keeps you in the safe zone while still letting you change shape freely.
Inputs and outputs that matter
- megapixel_scale (0.1–2.0, default 1) - your total pixel budget. Keep it near 1.0 for SDXL-class models; push higher only if your model was trained for it.
- aspect_ratio -
1:1,3:2,4:3,16:9,21:9. The shape dial. - is_portrait (boolean) - flip landscape to portrait.
- batch_size - how many latents to generate at once, i.e. how many images per run.
Outputs: LATENT wires into your sampler's latent input (KSampler, SamplerCustom, whatever you use). The width and height integers come out alongside so you can feed the computed dimensions to other nodes - an upscaler, a resize, a display - without recomputing them.
Installing it
ComfyUI Manager: search comfyui_dagthomas, install, restart. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/dagthomas/comfyui_dagthomas
cd comfyui_dagthomas
pip install -r requirements.txt
This node is pure tensor math - no API key, no model download. The pack's heavier dependencies are for its LLM and image-FX nodes.
Common issues
The most common surprise is a distorted or duplicated subject, and it's almost never this node's fault - it's megapixel_scale set too high for your model. A 2.0MP latent on a checkpoint trained at 1MP invites the classic double-body artifact. Drop back toward 1.0 and generate a proper resolution first, then upscale in a second pass if you want it bigger.
Also note this outputs a standard empty latent, so it suits SDXL and SD-1.5-style pipelines. If your model has its own dedicated latent or expects a particular channel count (some newer architectures do), use that model's matching empty-latent node instead. For the mainstream SDXL/Flux case, though, this is a clean drop-in that saves you from ever memorizing another resolution table.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| width | INT | 10240–16384 | — |
| height | INT | 10240–16384 | — |
| batch_size | INT | 11–4096 | — |
| megapixel_scale | FLOAT | 1.00.1–2 | — |
| aspect_ratio | COMBO | 1:1 | 5 options: 1:1, 3:2, 4:3, 16:9, 21:9 |
| is_portrait | BOOLEAN | false | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| LATENT | LATENT | — |
| width | INT | — |
| height | INT | — |