mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-05-03 22:02:51 +08:00
feat(api-nodes): allow custom resolutions for GPTImage2 node (#13631)
Some checks are pending
Python Linting / Run Ruff (push) Waiting to run
Python Linting / Run Pylint (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.10, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.11, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.12, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-unix-nightly (12.1, , linux, 3.11, [self-hosted Linux], nightly) (push) Waiting to run
Execution Tests / test (macos-latest) (push) Waiting to run
Execution Tests / test (ubuntu-latest) (push) Waiting to run
Execution Tests / test (windows-latest) (push) Waiting to run
Test server launches without errors / test (push) Waiting to run
Unit Tests / test (macos-latest) (push) Waiting to run
Unit Tests / test (ubuntu-latest) (push) Waiting to run
Unit Tests / test (windows-2022) (push) Waiting to run
Some checks are pending
Python Linting / Run Ruff (push) Waiting to run
Python Linting / Run Pylint (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.10, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.11, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.12, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-unix-nightly (12.1, , linux, 3.11, [self-hosted Linux], nightly) (push) Waiting to run
Execution Tests / test (macos-latest) (push) Waiting to run
Execution Tests / test (ubuntu-latest) (push) Waiting to run
Execution Tests / test (windows-latest) (push) Waiting to run
Test server launches without errors / test (push) Waiting to run
Unit Tests / test (macos-latest) (push) Waiting to run
Unit Tests / test (ubuntu-latest) (push) Waiting to run
Unit Tests / test (windows-2022) (push) Waiting to run
Signed-off-by: bigcat88 <bigcat88@icloud.com>
This commit is contained in:
parent
a7d82baa06
commit
38ecad8f8a
@ -415,8 +415,9 @@ class OpenAIGPTImage1(IO.ComfyNode):
|
|||||||
"1152x2048",
|
"1152x2048",
|
||||||
"3840x2160",
|
"3840x2160",
|
||||||
"2160x3840",
|
"2160x3840",
|
||||||
|
"Custom",
|
||||||
],
|
],
|
||||||
tooltip="Image size",
|
tooltip="Image size. Select 'Custom' to use the custom width and height (GPT Image 2 only).",
|
||||||
optional=True,
|
optional=True,
|
||||||
),
|
),
|
||||||
IO.Int.Input(
|
IO.Int.Input(
|
||||||
@ -445,6 +446,26 @@ class OpenAIGPTImage1(IO.ComfyNode):
|
|||||||
default="gpt-image-2",
|
default="gpt-image-2",
|
||||||
optional=True,
|
optional=True,
|
||||||
),
|
),
|
||||||
|
IO.Int.Input(
|
||||||
|
"custom_width",
|
||||||
|
default=1024,
|
||||||
|
min=1024,
|
||||||
|
max=3840,
|
||||||
|
step=16,
|
||||||
|
tooltip="Used only when `size` is 'Custom'. Must be a multiple of 16 (GPT Image 2 only).",
|
||||||
|
optional=True,
|
||||||
|
advanced=True,
|
||||||
|
),
|
||||||
|
IO.Int.Input(
|
||||||
|
"custom_height",
|
||||||
|
default=1024,
|
||||||
|
min=1024,
|
||||||
|
max=3840,
|
||||||
|
step=16,
|
||||||
|
tooltip="Used only when `size` is 'Custom'. Must be a multiple of 16 (GPT Image 2 only).",
|
||||||
|
optional=True,
|
||||||
|
advanced=True,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
outputs=[
|
outputs=[
|
||||||
IO.Image.Output(),
|
IO.Image.Output(),
|
||||||
@ -471,9 +492,9 @@ class OpenAIGPTImage1(IO.ComfyNode):
|
|||||||
"high": [0.133, 0.22]
|
"high": [0.133, 0.22]
|
||||||
},
|
},
|
||||||
"gpt-image-2": {
|
"gpt-image-2": {
|
||||||
"low": [0.0048, 0.012],
|
"low": [0.0048, 0.019],
|
||||||
"medium": [0.041, 0.112],
|
"medium": [0.041, 0.168],
|
||||||
"high": [0.165, 0.43]
|
"high": [0.165, 0.67]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
$range := $lookup($lookup($ranges, widgets.model), widgets.quality);
|
$range := $lookup($lookup($ranges, widgets.model), widgets.quality);
|
||||||
@ -503,6 +524,8 @@ class OpenAIGPTImage1(IO.ComfyNode):
|
|||||||
mask: Input.Image | None = None,
|
mask: Input.Image | None = None,
|
||||||
n: int = 1,
|
n: int = 1,
|
||||||
size: str = "1024x1024",
|
size: str = "1024x1024",
|
||||||
|
custom_width: int = 1024,
|
||||||
|
custom_height: int = 1024,
|
||||||
model: str = "gpt-image-1",
|
model: str = "gpt-image-1",
|
||||||
) -> IO.NodeOutput:
|
) -> IO.NodeOutput:
|
||||||
validate_string(prompt, strip_whitespace=False)
|
validate_string(prompt, strip_whitespace=False)
|
||||||
@ -510,7 +533,25 @@ class OpenAIGPTImage1(IO.ComfyNode):
|
|||||||
if mask is not None and image is None:
|
if mask is not None and image is None:
|
||||||
raise ValueError("Cannot use a mask without an input image")
|
raise ValueError("Cannot use a mask without an input image")
|
||||||
|
|
||||||
if model in ("gpt-image-1", "gpt-image-1.5"):
|
if size == "Custom":
|
||||||
|
if model != "gpt-image-2":
|
||||||
|
raise ValueError("Custom resolution is only supported by GPT Image 2 model")
|
||||||
|
if custom_width % 16 != 0 or custom_height % 16 != 0:
|
||||||
|
raise ValueError(f"Custom width and height must be multiples of 16, got {custom_width}x{custom_height}")
|
||||||
|
if max(custom_width, custom_height) > 3840:
|
||||||
|
raise ValueError(f"Custom resolution max edge must be <= 3840, got {custom_width}x{custom_height}")
|
||||||
|
ratio = max(custom_width, custom_height) / min(custom_width, custom_height)
|
||||||
|
if ratio > 3:
|
||||||
|
raise ValueError(
|
||||||
|
f"Custom resolution aspect ratio must not exceed 3:1, got {custom_width}x{custom_height}"
|
||||||
|
)
|
||||||
|
total_pixels = custom_width * custom_height
|
||||||
|
if not 655_360 <= total_pixels <= 8_294_400:
|
||||||
|
raise ValueError(
|
||||||
|
f"Custom resolution total pixels must be between 655,360 and 8,294,400, got {total_pixels}"
|
||||||
|
)
|
||||||
|
size = f"{custom_width}x{custom_height}"
|
||||||
|
elif model in ("gpt-image-1", "gpt-image-1.5"):
|
||||||
if size not in ("auto", "1024x1024", "1024x1536", "1536x1024"):
|
if size not in ("auto", "1024x1024", "1024x1536", "1536x1024"):
|
||||||
raise ValueError(f"Resolution {size} is only supported by GPT Image 2 model")
|
raise ValueError(f"Resolution {size} is only supported by GPT Image 2 model")
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user