EditUtils: Adaptive Longest Edge lrzjason
Let the Image Tell You
- image
- longest_edge
If you've ever dragged a 3000px photo into an EditUtils workflow and watched the sampler choke, this node is the fix you didn't know you needed. AdaptiveLongestEdge_EditUtils looks at whatever image you feed it and returns a single integer: the right ref_longest_edge for that image. You plug that number into a Config Preparer or EditTextEncode and let the size of the edit be decided by the size of the input, not by your memory of the last time it worked.
It's a tiny node, so let's be precise about the tiny thing it does. Give it an image plus a min_size and a max_size, and it measures the image's actual longest edge. If that edge already sits between your min and max, it hands it back (pulled up to min_size if it fell below). If the image is bigger than max_size, it divides the edge down by an integer factor so the result lands under max_size - and still won't let it drop below min_size. That integer-factor step is the part people skim past: it keeps the math clean so a 4096px image doesn't get scaled to some awkward 2345px that fights your VAE alignment later.
The defaults are sensible starting points: min_size 512, max_size 2048. Think of them as guardrails, not targets. A small reference doesn't need to be a 1024 latent - let the node tell you 512 is fine. A huge reference shouldn't blow past 2048 just because the model technically accepts it.
Where it earns its keep is chained with the rest of this pack: its longest_edge output (an INT) is exactly what ref_longest_edge on the Flux2Klein or Boogu Config Preparers wants. So instead of:
LoadImage → [you typing 1024 into a box]
you get:
LoadImage → AdaptiveLongestEdge → ConfigPreparer.ref_longest_edge
Same wire, but now every image gets a resolution scaled to itself, and you stop silently upscaling 640px crops into 1024 latents (which is how you get blurry refs) or burning VRAM on 2048+ latents for a photo that was 1800px to begin with.
One honest caveat: this only computes a number. It won't clamp your canvas, won't resize anything, and if you feed it a batch of different-sized images it uses the first frame's dimensions. Pair it with CropWithPadInfo_EditUtils on the way out if your workflow pads to a VAE unit and you want the original framing back.
Install comes free with the pack: grab lrzjason/ComfyUI-EditUtils through ComfyUI Manager (search "EditUtils") or git clone https://github.com/lrzjason/ComfyUI-EditUtils into custom_nodes, then restart. No pip installs, no model downloads - this pack is plumbing, and the model you're editing (Qwen-Image-Edit, Flux 2 Klein, Boogu, or Krea 2) is the part you bring yourself.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| min_size | INT | 51264–4096 | When image is smaller than min_size, it will be resized to at least the min_size. |
| max_size | INT | 2048512–4096 | When image is larger than max_size, it will be resized to under the max_size. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| longest_edge | INT | — |