ComfyUI Node

Gpt Image Auto Prepare

The node that goes in front of the edit model, so the way back still exists

By comrender·Created a day ago·Updated a day ago· 0
Gpt Image Auto Prepare
  • raw_image
  • edit_mask
  • image
  • mask
  • width
  • height
  • size
  • transform
  • info

Why this exists

Closed edit models are the one thing you can't run locally (closed-source-models.md), and they come with a dumb, unavoidable round trip: you hand over a 3678×4598 photo, you get back 2576×3216, and now you have an edited version of your image at a size your downstream nodes don't expect. You could eyeball a pad size and hand-fix it every time. Or you can put one node in front of the model that fits the whole frame into a canvas the model will accept, and records exactly how it did it so the other node can undo it.

That's Gpt Image Auto Prepare. It has no widgets at all - no sizing mode, no target width, no crop anchor. You give it an image and it decides. Verified in the source: the only inputs are raw_image and an optional edit_mask.

How it works

Two things happen, and the first one is the interesting bit.

It finds a canvas that survives its own round trip. Prepare calls the size policy, then feeds the resulting canvas back through the policy as if it were the input, over and over until the answer stops changing - with a hard cap of 256 iterations, after which it raises "Automatic GPT image sizing did not converge" rather than looping forever. Why bother? Because NanoSeed re-derives a size from whatever you hand it. A canvas that isn't a fixed point of that calculation comes back re-rounded one more time, and your recorded geometry no longer describes the image the model actually edited. The loop restricts you to canvases that are stable under the receiving node's own math.

It fits the whole frame, never crops. Scale is min(canvas_w/raw_w, canvas_h/raw_h), the image is bicubic-resized to that, and pasted into a zeroed (black) canvas at pad_left = round((canvas_w - resized_w)/2). Centered, uniform, no subject detection, no composition judgement. If you wanted a crop, that's the manual Gpt Image Size Calculator node, not this one.

Then it emits a transform - a version-1 mapping carrying raw width/height, canvas width/height, the resized content size, the pad offsets, and raw_batch. Restore doesn't take that on faith: it recomputes the expected centered fit from the raw dimensions and rejects anything that doesn't match ("GPT_IMAGE_TRANSFORM geometry does not describe centered uniform fit"). It's a checksum as much as a wire. You can't type one in - only Prepare emits it.

Inputs and outputs

Required: raw_image. Optional: edit_mask, the author's own description being "Optional raw-image mask; white pixels are editable." It must be at the original image's resolution, with a batch of 1 or matching the image.

Outputs: image (the padded canvas), mask, width, height, size (a "WxH" string), transform, and info. Wire image plus width/height into the generation node - the README's NanoSeed recipe is to keep that node at 4K - and transform into Gpt Image Auto Restore.

mask is worth understanding before you wire it. If you connect nothing, you get ones over the content rectangle and zeros over the padding. If you connect a mask, you get yours, resized and padded alongside the image. The README is blunt that this follows ComfyUI's white-means-edit convention but may not be the mask shape your generation node wants, and that for restoration you should use the original-resolution mask, not this resized output.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/comrender/ComfyUI-Gpt-Image-Size-Calculator.git

Restart, then search "Gpt Image Auto Prepare". ComfyUI Manager also has it under the pack title Gpt Image Size Calculator (registry id gpt-image-size-calculator, publisher comrender). Python 3.10+, no pip install, no models, no API key - pyproject.toml declares zero dependencies because ComfyUI's PyTorch is all it uses. Prepare and Restore arrived in v1.1.0; the calculator is older.

Gotchas

"Raw image" means the original ComfyUI IMAGE tensor, not a camera RAW decoder. People do ask.

Input validation is strict and it fails loudly: rank-4 NHWC float tensor, 1/3/4 channels, no NaN or infinity, masks clamped to 0–1. If a mask node upstream hands over values outside 0–1 you get a ValueError naming the input, which beats a silently wrong composite.

One original can be broadcast across several generated variations - the batch is recorded in the transform and Restore enforces it - but other batch combinations have to be compatible.

And the standing caveat: this stabilizes the size for the calculation it reimplements. If the node you feed is set to something else, it will re-derive and your canvas is a suggestion again. The pack is new, single-maintainer and MIT, with no community track record yet - which is why it matters that it's small enough to read, since node packs execute on import with no sandbox (comfyui-ecosystem.md).

Categoryimage

Inputs (2)

NameTypeDefaultDescription
raw_imageIMAGE
edit_maskoptMASKOptional raw-image mask; white pixels are editable.

Outputs (7)

NameTypeDescription
imageIMAGE
maskMASK
widthINT
heightINT
sizeSTRING
transformGPT_IMAGE_TRANSFORM
infoSTRING