From 7d6e7fa5d83fcd00bac7038a0976435def47fc32 Mon Sep 17 00:00:00 2001 From: Jony <951565127@qq.com> Date: Mon, 9 Nov 2026 11:41:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=20OpenAI=20=E5=AE=98=E6=96=B9?= =?UTF-8?q?=E6=94=BE=E5=BC=80=20GIF+=E5=8F=82=E8=80=83=E5=9B=BE=EF=BC=8CSV?= =?UTF-8?q?G=20=E4=BB=8D=E4=BB=85=E6=96=87=E7=94=9F=E5=9B=BE=EF=BC=9B?= =?UTF-8?q?=E6=9C=89=E8=92=99=E7=89=88=E7=A6=81=E7=94=A8=20GIF/SVG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- docs/architecture.md | 2 +- docs/development.md | 2 +- nodes/gpt_image.py | 2 +- tests/test_gpt_image_nodes.py | 39 +++++++++++++--- tests/test_gpt_image_quality_frontend.mjs | 29 ++++++++++++ tests/test_o1key_image_generator.py | 43 ++++++++++++++++- tests/test_o1key_image_generator_frontend.mjs | 8 ++++ tests/test_o1key_image_jobs.py | 46 +++++++++++++++---- utils/o1key_image_catalog.py | 6 ++- web/js/gptImageQuality.js | 23 ++++++++-- web/js/o1keyImageGenerator.js | 19 ++++++-- 12 files changed, 190 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index f725cf1..930292e 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ pip install -r requirements.txt --upgrade 模型列表支持 `GPT Image 2.5 Sunburst / Flare` 和 `GPT Image 2.6 Sunburst / Flare`。2.6 Sunburst 偏精修与细节还原,2.6 Flare 偏快速出图;新模型加入「o1key 图片生成」、独立 GPT Image 和 GPT Image 批量跑图节点,已有默认模型与工作流选项保持不变。四者与 GPT Image 2 使用相同的「智能 / 1K / 2K / 4K」分辨率和「智能、1:1、3:2、2:3、4:3、3:4、16:9、9:16」宽高比;特价、优质、企业线路分别调用模型 ID 的 `-sp`、`-sd` 和无后缀版本。 -GPT Image 2.6 新增「复杂度」:`low / medium / high`(默认 `high`),控制渲染前的规划强度,越高规划越充分、耗时越长。该控件仅选择 2.6 时显示,切回旧模型会隐藏并保留选择,旧模型请求省略 `complexity`。2.6 同样支持「超高 / 最高」质量。2.6 额外支持 SVG / GIF 输出(仅纯文生图,有参考图或蒙版时前端会隐藏并后端拒绝):GIF 会展开为 IMAGE 批帧,同时保留原始 GIF 文件:独立节点通过 FILE 路径与带 `animated` 标志的节点内预览播放;统一面板在保存格式为「原始」时会把 GIF 原样落到 output,并由保存节点以可播放方式预览;SVG 会落盘 `.svg`,并额外返回栅格化 IMAGE 预览(优先 cairosvg / ImageMagick / Inkscape,否则占位图)。GIF 控件 `帧数`(2–64,默认 9)与 `帧时长ms`(20–2000,默认 200,按 10ms 取整)仅在格式为 gif 时显示。独立 `markup` 标注图参数仍未接入;现有参考图、蒙版和前端图像编辑功能保持原有方式。更新后重启 ComfyUI 并硬刷新页面即可选择新模型与格式。 +GPT Image 2.6 新增「复杂度」:`low / medium / high`(默认 `high`),控制渲染前的规划强度,越高规划越充分、耗时越长。该控件仅选择 2.6 时显示,切回旧模型会隐藏并保留选择,旧模型请求省略 `complexity`。2.6 同样支持「超高 / 最高」质量。2.6 额外支持 SVG / GIF 输出(SVG 仅纯文生图,有参考图或蒙版时隐藏并拒绝;GIF 可带参考图走编辑引导动画,有蒙版时仍隐藏并拒绝):GIF 会展开为 IMAGE 批帧,同时保留原始 GIF 文件:独立节点通过 FILE 路径与带 `animated` 标志的节点内预览播放;统一面板在保存格式为「原始」时会把 GIF 原样落到 output,并由保存节点以可播放方式预览;SVG 会落盘 `.svg`,并额外返回栅格化 IMAGE 预览(优先 cairosvg / ImageMagick / Inkscape,否则占位图)。GIF 控件 `帧数`(2–64,默认 9)与 `帧时长ms`(20–2000,默认 200,按 10ms 取整)仅在格式为 gif 时显示。独立 `markup` 标注图参数仍未接入;现有参考图、蒙版和前端图像编辑功能保持原有方式。更新后重启 ComfyUI 并硬刷新页面即可选择新模型与格式。 面板式图片生成节点统一支持 Nano Banana 2.1 / 2 / Pro、GPT Image 2 与 Seedream 5.0 Pro。旧工作流中的 Nano Banana 2 Lite 和 Nano Banana 会在加载前迁移为 Nano Banana 2,避免重启后下拉选项变化导致参数错位。提示词右下角使用带 `✨` 图标的「AI帮写」按钮;独立 Nano Banana 节点不再提供提示词优化按钮。参数区采用 LiteGraph 原生参数控件,提示词和参考图保留自定义面板;模型、线路、分辨率、宽高比、生图数量等参数行由原生控件负责渲染并把标题和值放在同一个参数框内,种子保留一行紧凑的随机按钮;保留批量开关、参考图区、提示词内 AI 帮写和底部开始生成,控件颜色沿用当前 ComfyUI 主题,按钮不使用独立强调色;提示词区域不再显示额外标题,默认输入框展示约 3 行内容;随机种子按钮仍内嵌在种子输入框右侧。ComfyUI Nodes 1.0 因识别到 `seed` 输入而自动添加的「生成后控制」与该按钮功能重复,因此会由面板隐藏,不占用节点顶部空间。模型、线路、分辨率、宽高比、生图数量和种子常显;模型专属参数会随模型动态切换:仅 Nano Banana 2 / 2.1 显示「思考等级」,GPT Image 2 / 2.5 / 2.6 显示「质量」「背景」和「蒙版」,GPT Image 2 / 2.5 / 2.6 与 Seedream 5.0 Pro 都显示作为 API 参数的「输出格式」。这些参数不收进高级设置弹层;切换模型只隐藏不适用参数,不会清空已选值。分辨率新增默认值「智能」;选择它时,Nano Banana、GPT Image 和 Seedream 的上游请求都不发送 `size`,由模型决定输出尺寸。选择具体档位时,GPT Image 2 会把分辨率与宽高比映射为具体像素尺寸;宽高比选择「智能」时按正方形映射为 `1024x1024 / 2048x2048 / 2880x2880`。背景支持自动、透明和不透明,输出格式支持 JPEG、PNG 和 WebP;新建 GPT 设置默认 PNG,已有工作流保留保存的格式,其中透明背景只能搭配 PNG 或 WebP。所有模型每次请求最多使用 10 张参考图。GPT Image 新选项支持每条提示词生成 1–8 张,旧工作流中的 9 张仍可执行;其余模型保持 `1 / 2 / 4 / 9`。GPT Image 2.5 的质量另支持「超高 / 最高」,分别发送 `xhigh / max`;GPT Image 2 仅支持原有四档。提示词支持用独占一行的 `---` 分隔多条内容;所有模型和执行入口都会按“提示词数量 × 生图数量”生成任务,任务排列为同一提示词的所选张数在前、下一条提示词随后,单次最多 1000 个任务。任务会按受控并发分批执行,GPT Image 与 Seedream 请求中的 `n` 固定为 `1`。模型线路在面板中显示为「特价(便宜)/ 优质(小贵)/ 企业(贵)」,工作流内部仍保存兼容值「畅速 / 直连 / 专线」;新建节点的思考等级默认为「高」,显示为「低(耗时低,智力低)/ 高(耗时高,智力高)」;缩放图片默认为「智能缩放」,显示为「不缩放(无大图)/ 智能缩放(有大图)」。下拉菜单展开时可查看选项说明,收起后参数框只显示当前值。 同一面板支持 Nodes 1.0 / 2.0 切换,参数、参考图和操作位置保持不变。 diff --git a/docs/architecture.md b/docs/architecture.md index 949b5cd..414310f 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -276,7 +276,7 @@ Completed videos are atomically promoted into the configured output location wit - Unified GPT Image requests omit the retired moderation parameter. - `GPT Image 2.5 Sunburst / Flare` and `GPT Image 2.6 Sunburst / Flare` share GPT Image 2's resolution/aspect-ratio matrix and existing raster controls. Their `畅速 / 直连 / 专线` route values resolve to API IDs ending in `-sp / -sd /` no suffix, respectively; both newer series accept `xhigh / max` quality. - GPT Image 2.6 adds an append-only `复杂度` widget (unified index 23, after the existing layer-decomposition flag). The shared catalog validates `low / medium / high`, defaults to `high`, and omits the field for older models. Direct generation, standalone single/batch nodes, immutable background-job snapshots and client parallel fan-out carry the same selection. The control is hidden for other models without deleting its saved value. Existing node IDs, defaults and widget positions remain stable; older arrays use the appended widget's schema default. Standalone workflow migration temporarily removes a recognized complexity tail while existing tail-based rules run, then restores it; root and subgraph reloads remain idempotent. -- GPT Image 2.6 adds SVG/GIF to the gated output-format menu (not the 2.0/2.5 raster list). SVG/GIF are generation-only and reject reference images/masks. GIF requests may send `frame_count` / `frame_duration_ms`; results expand to an IMAGE frame batch while original GIF bytes are preserved for playable preview/save. SVG writes a `.svg` file and returns a rasterized IMAGE preview (cairosvg/ImageMagick/Inkscape when available; otherwise a placeholder preview). The separate provider `markup` input remains out of scope. +- GPT Image 2.6 adds SVG/GIF to the gated output-format menu (not the 2.0/2.5 raster list). SVG is generation-only and rejects reference images/masks; GIF may use reference images via image edit, but still rejects masks. GIF requests may send `frame_count` / `frame_duration_ms`; results expand to an IMAGE frame batch while original GIF bytes are preserved for playable preview/save. SVG writes a `.svg` file and returns a rasterized IMAGE preview (cairosvg/ImageMagick/Inkscape when available; otherwise a placeholder preview). The separate provider `markup` input remains out of scope. - The GPT Image batch node pairs every populated folder through its selected pairing mode and runs the resulting tasks concurrently. It has no random-folder selector or concurrency widget; workflow migration removes both values from older saved nodes. - The Nano Banana batch node's optional colour correction never resizes the generated image, uses only reference image 1, and runs exactly once after generation and before save; its standalone counterpart and `O1keyImageGenerator` have no correction stage. - Route-label changes never alter the serialized values `畅速`, `直连`, and `专线`. diff --git a/docs/development.md b/docs/development.md index 9a3fa40..a2b634f 100644 --- a/docs/development.md +++ b/docs/development.md @@ -76,7 +76,7 @@ When changing `O1keyImageSave`, preserve the mutually-exclusive preview rules do When adding a model to `O1keyImageGenerator`, update `utils/o1key_image_catalog.py`, the frontend model descriptions/capability switch, the job payload validator, and the model-family executor together. Preserve the existing route values even when their labels change. Provider-specific multi-image parameters must not bypass the unified scheduler: each selected output image is one concurrent provider request, and GPT Image always receives `n=1`. Keep GPT-only controls appended after the original generator widgets so old workflow arrays do not shift. -GPT Image 2.6's `复杂度` remains the last widget in both standalone schemas and at index 23 in the unified schema. Keep its catalog resolver shared by direct execution, background-job normalization/execution and the client. Older models omit `complexity` even if the hidden widget retains a value. SVG/GIF stay gated to GPT Image 2.6 via catalog helpers and frontend format menus; keep append-only `帧数` / `帧时长ms` after `复杂度`. Preserve GIF dual delivery (IMAGE frames + original bytes/path) and SVG path + raster preview. Run `test_gpt_image_nodes.py`, `test_o1key_image_generator.py`, `test_o1key_image_jobs.py`, `test_gpt_image_quality_frontend.mjs` and `test_o1key_image_generator_frontend.mjs`; preserve the nested-graph migration and complexity-value copy/paste cases. +GPT Image 2.6's `复杂度` remains the last widget in both standalone schemas and at index 23 in the unified schema. Keep its catalog resolver shared by direct execution, background-job normalization/execution and the client. Older models omit `complexity` even if the hidden widget retains a value. SVG/GIF stay gated to GPT Image 2.6 via catalog helpers and frontend format menus (SVG: text-to-image only; GIF: refs allowed, mask rejected); keep append-only `帧数` / `帧时长ms` after `复杂度`. Preserve GIF dual delivery (IMAGE frames + original bytes/path) and SVG path + raster preview. Run `test_gpt_image_nodes.py`, `test_o1key_image_generator.py`, `test_o1key_image_jobs.py`, `test_gpt_image_quality_frontend.mjs` and `test_o1key_image_generator_frontend.mjs`; preserve the nested-graph migration and complexity-value copy/paste cases. `utils/nano_banana_models.py` owns the shared Nano Banana model list and route IDs for `NanoBanana` and `BatchNanoBananaPro`; the unified image generator publishes the supported first three entries from that list. `Nano Banana 2.1` is first in the model lists and the default in all three schemas, the unified execution method, and frontend fallbacks. Its `畅速 / 直连 / 专线` IDs are `gemini-nano-banana-2.1-sp / gemini-nano-banana-2.1-sd / gemini-nano-banana-2.1`; it shares Nano Banana 2's thinking, online-search, and extended-aspect-ratio support. The unified node migrates retired `Nano Banana 2 Lite` and `Nano Banana` workflow values to `Nano Banana 2` before ComfyUI restores widgets; legacy standalone nodes keep recognizing their released values. Verify model IDs, defaults, migration, and parameter forwarding with the Nano Banana dynamic-input, unified image-generator, image-job, and image-generator frontend tests. diff --git a/nodes/gpt_image.py b/nodes/gpt_image.py index d232f58..bb4407e 100644 --- a/nodes/gpt_image.py +++ b/nodes/gpt_image.py @@ -195,7 +195,7 @@ class O1keyGPTImage(io.ComfyNode): "输出格式", options=GPT_IMAGE_26_OUTPUT_FORMAT_OPTIONS, default="png", - tooltip="2.6 另支持 svg / gif;svg/gif 仅纯文生图可用。", + tooltip="2.6 另支持 svg / gif;svg 仅纯文生图,gif 可带参考图、不支持蒙版。", ), io.Combo.Input( "背景", diff --git a/tests/test_gpt_image_nodes.py b/tests/test_gpt_image_nodes.py index e1fc72c..da08fa6 100644 --- a/tests/test_gpt_image_nodes.py +++ b/tests/test_gpt_image_nodes.py @@ -467,14 +467,41 @@ class GPTImage26SvgGifTests(unittest.TestCase): def test_svg_gif_reject_edit_inputs(self): import torch + from comfyui_o1key.utils.o1key_image_catalog import validate_gpt_image_vector_output + client = object.__new__(GptImageClient) fake = torch.zeros((1, 8, 8, 3)) - for output_format in ("svg", "gif"): - with self.assertRaisesRegex(ValueError, "纯文生图"): - client._build_async_generate_body( - "test", "gpt-image-2.6-sunburst", "high", None, 1, - image_list=[fake], output_format=output_format, - ) + with self.assertRaisesRegex(ValueError, "纯文生图"): + client._build_async_generate_body( + "test", "gpt-image-2.6-sunburst", "high", None, 1, + image_list=[fake], output_format="svg", + ) + # GIF + reference images is allowed (OpenAI image edit guidance). + validate_gpt_image_vector_output( + "gpt-image-2.6-sunburst", + "gif", + has_images=True, + has_mask=False, + ) + with self.assertRaisesRegex(ValueError, "纯文生图"): + validate_gpt_image_vector_output( + "gpt-image-2.6-sunburst", + "svg", + has_images=False, + has_mask=True, + ) + with self.assertRaisesRegex(ValueError, "不支持蒙版"): + validate_gpt_image_vector_output( + "gpt-image-2.6-sunburst", + "gif", + has_images=True, + has_mask=True, + ) + with self.assertRaisesRegex(ValueError, "不支持蒙版"): + client._build_async_generate_body( + "test", "gpt-image-2.6-sunburst", "high", None, 1, + image_list=[fake], mask_tensor=fake, output_format="gif", + ) def test_materialize_gif_expands_frames_and_keeps_bytes(self): from io import BytesIO diff --git a/tests/test_gpt_image_quality_frontend.mjs b/tests/test_gpt_image_quality_frontend.mjs index 649ad26..1827bcd 100644 --- a/tests/test_gpt_image_quality_frontend.mjs +++ b/tests/test_gpt_image_quality_frontend.mjs @@ -163,3 +163,32 @@ for (const nodeType of ["O1keyGPTImage", "O1keyGPTImageBatch"]) { assert.equal(format.options.values.includes(nodeType === "O1keyGPTImageBatch" ? "GIF" : "gif"), false); assert.equal(frameCount.hidden, true); } + +for (const nodeType of ["O1keyGPTImage", "O1keyGPTImageBatch"]) { + const node = makeNode("gpt-image-2.6-sunburst", "最高", nodeType); + const size = () => [150, 20]; + const complexity = { name: "复杂度", value: "中", options: {}, computeSize: size }; + const formatName = nodeType === "O1keyGPTImageBatch" ? "图片输出格式" : "输出格式"; + const gifValue = nodeType === "O1keyGPTImageBatch" ? "GIF" : "gif"; + const svgValue = nodeType === "O1keyGPTImageBatch" ? "SVG" : "svg"; + const format = { + name: formatName, + value: nodeType === "O1keyGPTImageBatch" ? "PNG" : "png", + options: { values: [] }, + callback() {}, + }; + const frameCount = { name: "帧数", value: 9, options: {}, computeSize: size }; + const frameDuration = { name: "帧时长ms", value: 200, options: {}, computeSize: size }; + node.widgets.push(complexity, format, frameCount, frameDuration); + extension.nodeCreated(node); + + node.widgets.push({ name: "参考图1", value: "ref.png", options: {} }); + node.modelWidget.callback(); + assert.equal(format.options.values.includes(gifValue), true, "refs keep gif"); + assert.equal(format.options.values.includes(svgValue), false, "refs hide svg"); + + node.widgets.push({ name: "遮罩", value: "mask.png", options: {} }); + node.modelWidget.callback(); + assert.equal(format.options.values.includes(gifValue), false, "mask hides gif"); + assert.equal(format.options.values.includes(svgValue), false, "mask hides svg"); +} diff --git a/tests/test_o1key_image_generator.py b/tests/test_o1key_image_generator.py index 4e65704..7a2dcc5 100644 --- a/tests/test_o1key_image_generator.py +++ b/tests/test_o1key_image_generator.py @@ -577,7 +577,7 @@ class O1keyImageGeneratorTests(unittest.TestCase): self.assertTrue(all("moderation" not in call for call in calls)) self.assertTrue(all(call["resize_mode"] == "智能缩放" for call in calls)) - def test_gpt_26_gif_sends_frame_fields_and_rejects_edit(self): + def test_gpt_26_gif_sends_frame_fields_and_vector_edit_rules(self): calls = [] class FakeClient: @@ -627,6 +627,47 @@ class O1keyImageGeneratorTests(unittest.TestCase): self.assertEqual(calls[0]["complexity"], "low") fake_ref = torch.zeros((1, 8, 8, 3), dtype=torch.float32) + gif_ref_calls = [] + + class FakeGifRefClient(FakeClient): + async def generate_image_async(self, **kwargs): + gif_ref_calls.append(kwargs) + return [Image.new("RGB", (6, 4), "blue")] + + with ( + patch( + "comfyui_o1key.nodes.o1key_image_generator.GptImageClient", + FakeGifRefClient, + ), + patch( + "comfyui_o1key.nodes.o1key_image_generator.get_base_url_by_route", + return_value="https://example.invalid", + ), + patch( + "comfyui_o1key.nodes.o1key_image_generator._load_reference_tensors", + return_value={0: fake_ref}, + ), + ): + gif_ref_result = asyncio.run(O1keyImageGenerator.execute( + prompt="一只宇航猫", + 模型="gpt-image-2.6-flare", + 模型线路="畅速", + 分辨率="智能", + 宽高比="1:1", + 生图数量=1, + 质量="自动", + 复杂度="低", + 输出格式="gif", + 帧数=12, + 帧时长ms=205, + 背景="auto", + 缩放图片="不缩放", + 参考图清单='[{"name":"a.png","subfolder":"","type":"input"}]', + )) + self.assertEqual(tuple(gif_ref_result[0].shape), (1, 4, 6, 3)) + self.assertEqual(gif_ref_calls[0]["output_format"], "gif") + self.assertIsNotNone(gif_ref_calls[0].get("image_tensor")) + with ( patch( "comfyui_o1key.nodes.o1key_image_generator._load_reference_tensors", diff --git a/tests/test_o1key_image_generator_frontend.mjs b/tests/test_o1key_image_generator_frontend.mjs index e39f3d0..5516361 100644 --- a/tests/test_o1key_image_generator_frontend.mjs +++ b/tests/test_o1key_image_generator_frontend.mjs @@ -4880,7 +4880,15 @@ const nanoThinkingSource = fs.readFileSync(new URL("../web/js/nanoBananaThinking assert.equal(node._o1igFrameDurationField.style.display, ""); node._o1igReferences = [{ name: "a.png", subfolder: "", type: "input" }]; syncGptOutputOptions(node); + assert.equal(node._o1igOutputFormat._o1igOptions.some((option) => option.value === "gif"), true); + assert.equal(node._o1igOutputFormat._o1igOptions.some((option) => option.value === "svg"), false); + assert.equal(node._o1igOutputFormat.value, "gif"); + assert.equal(node._o1igFrameCountField.style.display, ""); + assert.equal(node._o1igFrameDurationField.style.display, ""); + node._o1igMask = { name: "mask.png", subfolder: "", type: "input" }; + syncGptOutputOptions(node); assert.equal(node._o1igOutputFormat._o1igOptions.some((option) => option.value === "gif"), false); + assert.equal(node._o1igOutputFormat._o1igOptions.some((option) => option.value === "svg"), false); } { diff --git a/tests/test_o1key_image_jobs.py b/tests/test_o1key_image_jobs.py index 379b210..654c1f7 100644 --- a/tests/test_o1key_image_jobs.py +++ b/tests/test_o1key_image_jobs.py @@ -163,14 +163,44 @@ class PayloadTests(unittest.TestCase): "model": "gpt-image-2.5-sunburst", "output_format": output_format, }) - with self.assertRaisesRegex(ValueError, "纯文生图"): - JOBS.normalize_job_payload({ - **_payload(), - "batch_id": str(__import__("uuid").uuid4()), - "model": "gpt-image-2.6-flare", - "output_format": output_format, - "references": [{"name": "a.png", "subfolder": "", "type": "input"}], - }) + with self.assertRaisesRegex(ValueError, "纯文生图"): + JOBS.normalize_job_payload({ + **_payload(), + "batch_id": str(__import__("uuid").uuid4()), + "model": "gpt-image-2.6-flare", + "output_format": "svg", + "references": [{"name": "a.png", "subfolder": "", "type": "input"}], + }) + gif_with_refs = JOBS.normalize_job_payload({ + **_payload(), + "batch_id": str(__import__("uuid").uuid4()), + "model": "gpt-image-2.6-flare", + "output_format": "gif", + "frame_count": 12, + "frame_duration_ms": 205, + "references": [{"name": "a.png", "subfolder": "", "type": "input"}], + }) + self.assertEqual(gif_with_refs["output_format"], "gif") + self.assertEqual(gif_with_refs["frame_count"], 12) + self.assertEqual(len(gif_with_refs["references"]), 1) + with self.assertRaisesRegex(ValueError, "纯文生图"): + JOBS.normalize_job_payload({ + **_payload(), + "batch_id": str(__import__("uuid").uuid4()), + "model": "gpt-image-2.6-flare", + "output_format": "svg", + "references": [{"name": "a.png", "subfolder": "", "type": "input"}], + "mask": {"name": "mask.png", "subfolder": "", "type": "input"}, + }) + with self.assertRaisesRegex(ValueError, "不支持蒙版"): + JOBS.normalize_job_payload({ + **_payload(), + "batch_id": str(__import__("uuid").uuid4()), + "model": "gpt-image-2.6-flare", + "output_format": "gif", + "references": [{"name": "a.png", "subfolder": "", "type": "input"}], + "mask": {"name": "mask.png", "subfolder": "", "type": "input"}, + }) with self.assertRaisesRegex(ValueError, "帧数"): JOBS.normalize_job_payload({ **_payload(), diff --git a/utils/o1key_image_catalog.py b/utils/o1key_image_catalog.py index 072441b..58c9e73 100644 --- a/utils/o1key_image_catalog.py +++ b/utils/o1key_image_catalog.py @@ -210,8 +210,10 @@ def validate_gpt_image_vector_output( fmt = resolve_gpt_image_output_format(model, output_format) if fmt not in GPT_IMAGE_26_EXTRA_OUTPUT_FORMAT_OPTIONS: return - if has_images or has_mask: - raise ValueError("SVG / GIF 仅支持纯文生图,不能带参考图或蒙版") + if fmt == "svg" and (has_images or has_mask): + raise ValueError("SVG 仅支持纯文生图,不能带参考图或蒙版") + if fmt == "gif" and has_mask: + raise ValueError("GIF 输出不支持蒙版") def is_gpt_image_model(model: str) -> bool: diff --git a/web/js/gptImageQuality.js b/web/js/gptImageQuality.js index 2a63685..7e59ed8 100644 --- a/web/js/gptImageQuality.js +++ b/web/js/gptImageQuality.js @@ -27,8 +27,18 @@ function setWidgetHidden(widget, hidden) { } else delete widget.computeSize; } -function hasReferenceOrMask(node) { +function hasMask(node) { if (findWidget(node, "遮罩")?.value) return true; + // Connected inputs on modern nodes are not always mirrored into widget values. + const inputs = node.inputs || []; + for (const input of inputs) { + if (!input || input.link == null) continue; + if (input.name === "遮罩") return true; + } + return false; +} + +function hasReference(node) { const widgets = node.widgets || []; for (const widget of widgets) { if (/^参考图/.test(widget.name) && widget.value) return true; @@ -37,7 +47,7 @@ function hasReferenceOrMask(node) { const inputs = node.inputs || []; for (const input of inputs) { if (!input || input.link == null) continue; - if (input.name === "遮罩" || /^参考图/.test(input.name) || input.name === "参考图组") { + if (/^参考图/.test(input.name) || input.name === "参考图组") { return true; } } @@ -77,12 +87,15 @@ function updateQualityOptions(node) { const formatWidget = findWidget(node, "输出格式") || findWidget(node, "图片输出格式"); const isBatch = (node.comfyClass || node.type) === "O1keyGPTImageBatch"; if (formatWidget) { - const blocked = hasReferenceOrMask(node); let values = isBatch ? (is26 ? BATCH_26 : BATCH_RASTER) : (is26 ? FORMAT_26 : RASTER_FORMATS); - if (is26 && blocked) { - values = values.filter((value) => !/^(svg|gif|SVG|GIF)$/i.test(value)); + if (is26) { + if (hasMask(node)) { + values = values.filter((value) => !/^(svg|gif|SVG|GIF)$/i.test(value)); + } else if (hasReference(node)) { + values = values.filter((value) => !/^(svg|SVG)$/i.test(value)); + } } formatWidget.options ??= {}; formatWidget.options.values = [...values]; diff --git a/web/js/o1keyImageGenerator.js b/web/js/o1keyImageGenerator.js index 3b85ea9..b8fc3f2 100644 --- a/web/js/o1keyImageGenerator.js +++ b/web/js/o1keyImageGenerator.js @@ -119,7 +119,7 @@ const GPT_OUTPUT_FORMATS = [ ]; const GPT_26_EXTRA_OUTPUT_FORMATS = [ { value: "svg", label: "SVG", description: "矢量,仅纯文生图" }, - { value: "gif", label: "GIF", description: "动图,仅纯文生图" }, + { value: "gif", label: "GIF", description: "动图,可带参考图引导动画" }, ]; const SEEDREAM_RESOLUTIONS = ["智能", "1K", "2K"]; const SEEDREAM_LAYER_RESOLUTIONS = ["智能", "1K", "1.5K", "2K"]; @@ -1537,11 +1537,20 @@ function syncGptOutputOptions(node) { formats = SEEDREAM_OUTPUT_FORMATS; } else { const is26 = /^gpt-image-2\.6-/.test(String(model || "")); - const hasRefs = (node._o1igReferences || []).length > 0 - || (node._o1igModelReferences || []).length > 0 - || Boolean(node._o1igMask); + const hasImages = (node._o1igReferences || []).length > 0 + || (node._o1igModelReferences || []).length > 0; + const hasMask = Boolean(node._o1igMask); formats = [...GPT_OUTPUT_FORMATS]; - if (is26 && !hasRefs) formats = [...formats, ...GPT_26_EXTRA_OUTPUT_FORMATS]; + if (is26) { + if (!hasImages && !hasMask) { + formats = [...formats, ...GPT_26_EXTRA_OUTPUT_FORMATS]; + } else if (hasImages && !hasMask) { + formats = [ + ...formats, + ...GPT_26_EXTRA_OUTPUT_FORMATS.filter((option) => option.value === "gif"), + ]; + } + } if (node._o1igBackground.value === "transparent") { formats = formats.filter((option) => option.value !== "jpeg" && option.value !== "svg" && option.value !== "gif"); }