Nodes/comfyui_qwen_edit_pixel_perfect/Pre-Crop to Qwen (Drift-Free)
ComfyUI Node

Pre-Crop to Qwen (Drift-Free)

Stop the drift before it starts — crop to the size Qwen can't resize

By oron1208·Created 2 months ago·Updated 2 months ago· 15
Pre-Crop to Qwen (Drift-Free)
  • image
  • cropped
crop_anchorcenter
force_minimumtrue

The Align to Reference (AKAZE) node in this pack fixes Qwen's drift after the fact. Pre-Crop to Qwen (Drift-Free) is the other approach, and it's arguably the more elegant one: make the drift impossible in the first place.

Here's the setup. Qwen-Image-Edit's text encoder internally resizes every input with a deterministic function: scale to a 1024×1024 area, then round each dimension down to a multiple of 8. Write that as f(W,H), and you'll find some image sizes are fixed points - feed in (W,H), and f(W,H) returns exactly (W,H). For those sizes, the resize is a no-op, and there's nothing left to drift. This node searches for the fixed point closest to your source's aspect ratio, center-crops the source to exactly that size, and hands you an image Qwen physically cannot resize.

That's the math-y version. The practical version: this is the node to put between your LoadImage and the Qwen encoder when you need repeatable, pixel-stable edits and you're OK trading a bit of frame for it.

How it works

It computes a drift-free (w,h) near 1MP whose aspect ratio matches your source as closely as possible, then crops the source to it. Output is the cropped image, ready to feed straight into the Qwen text encoder. After generation, you restore the full resolution with the pack's Upscale to Original Size node - that pairing is the whole "preventive" workflow, and the pack ships it as a ready-made JSON.

The crop is what you pay for the zero-drift guarantee. Qwen re-emits the whole frame, so a smaller crop means a smaller edit canvas, and you lose the edges of your original.

The inputs that matter

  • image - your source image.
  • crop_anchor - where the crop bites when the source is bigger than the target. center is the default and usually right; pick topleft/topright/bottomleft/bottomright when you'd rather sacrifice a specific edge than a symmetric strip.
  • force_minimum - default true. If your source is smaller than the computed drift-free size, it upscales the source to reach it. Leave it on; turning it off lets Qwen run at a smaller-than-ideal size and is a quality gamble.

Gotchas

Be honest about what "zero drift" covers. The README is specific: the reference_latents path is fully zeroed, but the VL (384-area) image path that the vision-language model sees carries a tiny residual - small enough that nobody composites by it, but it's not a claim of nothing-at-all, everywhere. If you need a hard bit-identical guarantee, the mask-based nodes are the ones doing that.

And the crop trade-off is the whole decision. Don't want to lose any of the frame? That's what the AKAZE corrective node is for. The two approaches in this pack are literally a menu: preserve the frame and correct afterwards, or crop first and never drift.

Installing it

ComfyUI Manager → search comfyui_qwen_edit_pixel_perfect → install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/oron1208/comfyui_qwen_edit_pixel_perfect

Restart. No OpenCV needed for this one - it's pure torch, and there are no model files to download. Like the rest of the pack it targets the newer comfy_api.latest / io.Schema node API, so update ComfyUI if the nodes refuse to register. If the "Preventive (Drift-Free)" workflow complains about the pack at all, that stale-ComfyUI check is the first thing to verify.

Categoryimage/transform

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
crop_anchorCOMBOcenterWhere to anchor the crop when the source is larger than the target.
force_minimumBOOLEANtrueIf the source is smaller than the computed drift-free size, upscale it to reach the target (otherwise allow a smaller target).

Outputs (1)

NameTypeDescription
croppedIMAGEDrift-free crop ready to feed into Qwen.