Nodes/GPT-Image (OpenAI-compatible)/GPT-Image 尺寸规范化 (16倍数/边长)
ComfyUI Node

GPT-Image 尺寸规范化 (16倍数/边长)

Snapping your image size for gpt-image-2

By meomeo-dev·Created 2 months ago·Updated about a month ago· 1
GPT-Image 尺寸规范化 (16倍数/边长)
    1024
    1024
    步长16
    最小边16
    最大边3840

    The guard rail for "just type a number"

    GPT Image 2 is picky about dimensions in a way that's easy to stub your toe on: width and height must be multiples of 16, the longest edge caps at 3840, and every edge has to stay in range. Type 1007x1535 into the generation node out of habit and you'll get a request-time validation error, or worse, a server-side 400 after paying for the round trip. GPTImageSizeSnap (displayed "GPT-Image 尺寸规范化 (16倍数/边长)") is the fix for exactly that: you feed it whatever numbers you feel like typing, and it spits back the legal ones.

    It's a pure utility node - no API calls, no key, no network. If you already know gpt-image-2's constraints by heart you can skip it entirely. If you don't, it's cheaper than memorizing them.

    How it works

    Take a 宽 and 高 (both INT, required), snap each one to the nearest multiple of 「步长」 (default 16), then clamp to the 「最小边」/「最大边」 range (defaults 16 and 3840). The rounding is round-half-up to the nearest multiple, and the range bounds themselves get aligned to the step so the result is always both a multiple and in range - if you ask for a 3900 edge it comes back 3840, ask for 7 and you get 16. Two INT outputs, 「宽」 and 「高」, go straight into the GPTImageGenerate or GPTImageEdit node's 宽/高 inputs. To wire them in, right-click the width/height widget on the target node and convert it to an input - that's the "wire an INT into a number box" move.

    One honest limitation: it only handles the step-multiple and edge-range rules. The 1:3–3:1 aspect ratio and total-pixel checks still run at request time in the generation node, because those depend on both dimensions together. So this won't rescue a 1:10 canvas - but it will stop you from being rejected for a weird non-16 number, which is the case that actually bites people.

    Install and use

    It ships in the meomeo-dev/custom-gpt-image-2-api pack alongside the config, generate, and edit nodes - install the pack and you get all four:

    cd ComfyUI/custom_nodes
    git clone https://github.com/meomeo-dev/custom-gpt-image-2-api.git
    cd custom-gpt-image-2-api
    pip install -r requirements.txt   # requests, Pillow, numpy
    

    Restart ComfyUI. If you're mid-workflow, the practical recipe is: a GPTImageSizeSnap with its 宽/高 outputs wired to the generate node's 宽/高 inputs, set 步长 to 16 (leave it unless your gateway wants something else), and forget about it. The defaults are already aligned to gpt-image-2's spec, so nine times out of ten you change nothing.

    The one gotcha

    The two range widgets can be set against each other - a 最小边 above your 最大边. The node resolves that by letting the minimum win, so you get a consistent size rather than an error. It's a graceful touch, but it's also a sign you should double-check your numbers, because the result is probably not what you meant. Also worth knowing: because it's a deterministic math node, it doesn't disable ComfyUI's cache the way the generation node does - same inputs, same output, every time, and that's correct.

    CategoryGPT-Image

    Inputs (5)

    NameTypeDefaultDescription
    INT10240–8192
    INT10240–8192
    步长optINT161–256圆整到该值的倍数;gpt-image-2 要求 16。
    最小边optINT160–8192输出每条边不小于此值(会向上对齐到步长倍数)。
    最大边optINT38401–8192输出每条边不大于此值(会向下对齐到步长倍数)。默认 3840 对齐 gpt-image-2 最长边。

    Outputs (2)

    NameTypeDescription
    INT
    INT