Nodes/Comfyui-QwenEditUtils/Crop With Pad Info
ComfyUI Node

Crop With Pad Info

Crop a Qwen edit result back to its original content

By lrzjason·Created 11 months ago·Updated 6 months ago· 834
Crop With Pad Info
  • image
  • pad_info
  • cropped_image
  • scale_by

This is the back half of the pack's answer to Qwen edit's most annoying quirk. The encoder nodes can pad your image to a size the model likes, run the edit, and hand you a pad_info dictionary describing exactly how much padding they added and how they scaled things. CropWithPadInfo takes that dictionary and the generated result, and crops the padding back off - so you end up with an edit at your original content dimensions instead of one floating inside a padded canvas. Pad going in, crop coming out. That's the whole loop.

Why bother padding at all? Because Qwen-Image-Edit re-emits the entire frame and is fussy about input geometry - feed it an awkward size and the output comes back subtly offset or blurred. Padding to a size the model wants is how you avoid that; this node is what undoes the padding afterward so the fix is invisible in your final image.

How it works

The pad_info dictionary carries the numbers the encoder recorded: the x/y offset, the width and height of the real content, and the scale factor applied. CropWithPadInfo reads those, slices the padded region away from the image you give it, and returns just the original content area - plus the scale factor on its own output, in case you want to reverse the scaling too. No guessing about margins; it's using the exact values the padding step wrote down.

The inputs and outputs that matter

Both required:

  • image - the image to crop. Normally this is your generated/decoded result after the KSampler and VAE Decode, i.e. the padded output you want trimmed.
  • pad_info - the ANY dictionary from an encoder's pad_info output (Advance, Pro, or via QwenEditOutputExtractor off the Custom node). This must be the pad_info that matches the image you padded, or the crop math won't line up.

Outputs:

  • cropped_image - the IMAGE at original content dimensions, padding removed.
  • scale_by - the FLOAT scale factor from the original processing, handy if you want to rescale to exact source size afterward.

Installing it

Ships 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 or dependencies; it sits under the image category.

Common issues

The cardinal rule: the pad_info you feed in has to be the one produced for that image, from the same run. Mix a pad_info from one edit with the output of another and the crop lands in the wrong place. That also means you only get a meaningful crop if the encoder actually padded - set crop_method to pad (not center or disabled) upstream, or there's no padding to remove and the pad_info won't describe one. Use the scale_by output if your padded result also got scaled and you need to return to exact source pixels. This node is one piece of the crop-and-stitch pattern the community leans on to keep Qwen's whole-frame editing from quietly shifting everything you didn't ask it to touch.

Categoryimage

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
pad_infoANY

Outputs (2)

NameTypeDescription
cropped_imageIMAGE
scale_byFLOAT