Nodes/ComfyUI Warper Nodes/Preprocess for Target (Warper)
ComfyUI Node

Preprocess for Target (Warper)

Fit any image to a fixed canvas without cropping it

By AIWarper·Created about a year ago·Updated 8 months ago· 14
Preprocess for Target (Warper)
  • image
  • image
  • preprocess_data
target_resolutions672, 1568 688, 1504 720, 1456 752, 1392 800, 1328 832, 1248 880, 1184 944, 1104 1024, 1024 1104, 944 1184, 880 1248, 832 1328, 800 1392, 752 1456, 720 1504, 688 1568, 672
padding_typemirror
padding_colorblack

Instruction-editing models like Flux Kontext want a fixed canvas, but your input image is never that canvas. The classic answer - resize-to-fit-and-pad - smears or bars the image, and cropping throws away content. Preprocess for Target (Warper) solves it properly: it resizes your image to fit inside the best-matching resolution from your list, then pads the leftover space with mirrored edges by default, so the border continues the image instead of being a flat bar. The trick is that it records everything needed to undo it, and its partner Crop and Restore (Warper) does exactly that after your generation. Padding in, clean image out.

It's from ComfyUI Warper Nodes, the niche pack by workflow author AIWarper - and the pack ships an example workflow built around Flux Kontext using precisely this node pair. If you edit images with a fixed-canvas model, this is the preprocessing you've been rebuilding by hand.

How it works

The target_resolutions input is a multiline list of width, height pairs - and the default is the list the author built for Kontext: 17 resolutions from 672×1568 up through 1568×672, all the way around to 1024×1024. The node parses that list (it also accepts width x height or (w, h) formats), finds the resolution whose aspect ratio is closest to your source, scales the image to fit inside it with Lanczos, then pads. padding_type "mirror" reflects edge pixels - seamless for natural images, though weird for heavily textured edges - while "colored" fills with padding_color (black/grey/white). Outputs are the padded image and a preprocess_data blob recording original size, crop box, processed size, and scale ratio.

Inputs you'll actually touch:

  • image - source. One honest caveat: only the first frame of a batch is processed, so this is a single-image node.
  • target_resolutions - edit the defaults if your model needs a different set.
  • padding_type / padding_color - mirror is the default for a reason; colored padding is for when mirror edges confuse the model.

Installing it

Standard Warper install: ComfyUI Manager → search "ComfyUI-WarperNodes" → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/AIWarper/ComfyUI-WarperNodes
# restart ComfyUI

Needs PIL and numpy, both in any working ComfyUI. No model download - the README's RAFT checkpoint is only for Flow Visualizer.

Common issues

Mirror padding is great until it isn't: on images with strong repeating texture at the edges, the mirrored reflection can look like content and the model may try to edit it. Switch to colored padding if you see phantom borders in output. Because only image[0] is processed, feeding a batch silently drops frames - a real trap for anyone trying to use this in a video chain; the node is designed for single-image editing passes. And keep preprocess_data wired straight to Crop and Restore - losing that wire means you can't undo the pad, and you'll be hand-cropping output like it's 2023. Finally, the resolution pick is purely aspect-ratio-based: a square image fed a list with no near-square entry will still snap to the closest thing, which is mathematically right but may not be what you wanted.

CategoryWarper Tools/Preprocessing

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
target_resolutionsSTRING672, 1568 688, 1504 720, 1456 752, 1392 800, 1328 832, 1248 880, 1184 944, 1104 1024, 1024 1104, 944 1184, 880 1248, 832 1328, 800 1392, 752 1456, 720 1504, 688 1568, 672
padding_typeCOMBOmirror2 options: mirror, colored
padding_colorCOMBOblack3 options: black, grey, white

Outputs (2)

NameTypeDescription
imageIMAGE
preprocess_dataPREPROCESS_DATA