Orient Latent
Force any latent into portrait, landscape, or square — without leaving latent space
- samples
- LATENT
Let's say you're building a workflow that has to hand every job to the final sampler as a portrait frame - or a landscape frame, or a clean square - no matter what shape the incoming latent is. ComfyUI ships Rotate Latent (90° steps) and Flip Latent, but both are dumb: they rotate on command and leave you to figure out which way your latent is actually facing. Orient Latent (LatentOrient) is the "just make it right" version. You tell it one of five target shapes and it does whatever the math requires - rotate, crop, pad, or resize - to get there. No prompts, no models, no API.
This is a genuinely thin node, and that's the point. It sits on a latent and returns a latent; it never touches pixels. Everything happens in the compressed 8x-downsampled space your model actually denoises in, so a rotation here costs a few microseconds and - more importantly - you skip the decode-then-re-encode round trip through the VAE that would smear fine detail on SD 1.5.
How it works
The node reads your latent's current height and width from the tensor shape, then applies one of five branches:
- portrait - if the latent is wider than it is tall, it rotates 90° so height wins.
- landscape - same logic inverted; only rotates if height exceeds width.
- min square - center-crops to the smaller side, so you lose the long edge.
- max square - pads the shorter side with zeros up to the larger dimension, keeping all your content.
- avg square - bilinear-resizes both dimensions to the average of the two.
The smart part is the guards: if your latent is already portrait, portrait is a no-op pass-through. If it's already square, all three square modes no-op. Rotations are a clean torch.rot90 in latent space - no interpolation, so no quality cost at all.
The two inputs and the gotchas
You only set two things: samples (your LATENT, straight from a sampler or Empty Latent Image) and orientation, the five-way dropdown above. The single LATENT output wires straight into whatever comes next - KSampler, another latent transform, or a VAE decode.
Where people get burned:
max squarepads with zeros, not white. Zero-valued latent pixels decode to a muddy gray, so a 1024×768 latent forced to 1024×1024 gets visible gray bars top and bottom. If you want clean edges, do the padding in image space after decode instead - or just accept the bars and crop later.min squarethrows content away. The center crop is where the action usually is, but it is a destructive crop, so use it before the final sampler, not after you've already generated detail you want to keep.- It only ever acts when the shape is "wrong." Feed a portrait latent into
portraitand nothing visibly happens - that's correct behavior, not a bug.
Install and dependencies
Install is the usual two-liner with zero extras - there are no dependencies, no model files, no weights to download:
cd ComfyUI/custom_nodes
git clone https://github.com/SparknightLLC/ComfyUI-LatentOrientation
Then restart ComfyUI. Or, easier: ComfyUI Manager → Install Custom Nodes → search "ComfyUI-LatentOrientation" and hit Install. The pack ships a single node, category latent/transform, so search "Orient Latent" in the node picker after restart. If it doesn't show up, restart once more - the registry refresh lags behind the install sometimes.
When you'd actually reach for it
Reach for it when orientation is a constraint, not a choice: an img2img batch ingesting mixed-ratio source images that all have to come out portrait, a workflow that generates landscape for a banner slot regardless of what you sampled, or a square-only pipeline where min square normalizes every input before it hits a fixed-resolution model. If you just want to flip something once, use the built-in node - this one earns its keep automating the decision, not doing the turn.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| samples | LATENT | — | |
| orientation | COMBO | 5 options: portrait, landscape, min square, max square, avg square |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LATENT | LATENT | — |