Qwen Edit Adaptive Longest Edge
Auto-pick a safe longest edge before you edit
- image
- longest_edge
A small node that saves you from a specific headache: feeding Qwen-Image-Edit an image that's too big and watching it eat your VRAM or come back wrong. Give it your input image and a ceiling, and it computes a sensible longest-edge size - never above your max - that you can pipe into the resolution setting of the encoder nodes. It's the "figure out the right size for me" node, so you don't hard-code a resolution that's fine for one image and disastrous for the next.
This matters more than it looks, because Qwen edit is genuinely picky about input resolution. The model re-emits the whole frame, and if the geometry is off the output arrives offset or blurred - controlling the input size is the documented fix. Oversized inputs are also just expensive. Adaptive Longest Edge automates the guardrail.
How it works
It reads the dimensions of the input image, finds the longer of width and height, and compares it to your max_size. If the image is already within the limit, you get its actual longest edge back. If it's over, the node scales that number down to fit under the cap and returns the reduced value. The output is a single integer - a size, not an image - meant to drive a longest-edge or resolution input somewhere downstream (for example the ref_longest_edge on a config node).
The inputs and outputs that matter
Both inputs are required:
- image - the picture you're about to process. Only its dimensions are used.
- max_size - the ceiling for the longest edge, default 2048, range 512–4096. Set this to whatever your VRAM and the model comfortably handle; 2048 is a reasonable cap on a healthy card, drop it to 1536 or 1024 if you're tight.
Output: longest_edge - an INT. Wire it into the resolution/longest-edge input of your encoder or config node.
Installing it
Comes with the pack. ComfyUI Manager: search Comfyui-QwenEditUtils, install, restart. Or cd ComfyUI/custom_nodes && git clone https://github.com/lrzjason/Comfyui-QwenEditUtils, then restart. No models, no dependencies.
Common issues
Understand what it does and doesn't do: it only downscales the target - if your image is smaller than max_size it returns the image's real longest edge and won't upscale past it, which is usually what you want but occasionally surprises people expecting a fixed output size. It also outputs a number, not a resized image; the actual resize happens in whichever encoder node consumes the value, so nothing changes until you wire it up. And it doesn't snap to the specific sizes Qwen likes on its own - it just enforces a ceiling - so if you're chasing the last bit of alignment, pair it with a pad crop method (and the pad_info/CropWithPadInfo path) rather than expecting this node alone to solve the offset problem.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| 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 | — |