Add MJ image node, GIF save, and Kling/image generator updates

Ship o1key MJ图片生成 with content/style refs and prompt flags, save-GIF with preview, Kling 4.0 helpers, plus GPT/unified image node polish and docs.
This commit is contained in:
Jony
2026-11-09 09:11:12 +08:00
parent ff1cf830fa
commit a181cc1768
40 changed files with 6711 additions and 675 deletions
+99 -32
View File
@@ -23,6 +23,7 @@ from ..clients.seedream_image_client import (
from ..utils.config import get_api_key_or_raise, get_base_url_by_route
from ..utils.http2_client import create_http_client
from ..utils.image_utils import (
IMAGE_BATCH_MODE_ALIASES,
IMAGE_BATCH_MODE_GROUP_TO_MODELS,
IMAGE_BATCH_MODE_SINGLE_REFERENCES,
IMAGE_BATCH_MODES,
@@ -36,6 +37,19 @@ from ..utils.o1key_image_catalog import (
BANANA_RESOLUTION_OPTIONS,
GPT_IMAGE_ASPECT_RATIO_OPTIONS,
GPT_IMAGE_BACKGROUND_OPTIONS,
GPT_IMAGE_COMPLEXITY_OPTIONS,
resolve_gpt_image_complexity,
resolve_gpt_image_frame_count,
resolve_gpt_image_frame_duration_ms,
resolve_gpt_image_output_format,
validate_gpt_image_vector_output,
GPT_IMAGE_26_OUTPUT_FORMAT_OPTIONS,
GPT_IMAGE_GIF_FRAME_COUNT_DEFAULT,
GPT_IMAGE_GIF_FRAME_COUNT_MAX,
GPT_IMAGE_GIF_FRAME_COUNT_MIN,
GPT_IMAGE_GIF_FRAME_DURATION_DEFAULT,
GPT_IMAGE_GIF_FRAME_DURATION_MAX,
GPT_IMAGE_GIF_FRAME_DURATION_MIN,
GPT_IMAGE_COUNTS,
GPT_IMAGE_EXACT_SIZE_OPTIONS,
GPT_IMAGE_OUTPUT_FORMAT_OPTIONS,
@@ -258,6 +272,9 @@ async def _generate_gpt_images(
resize_mode: str,
output_format: str,
background: str,
complexity: str | None = None,
frame_count: int | None = None,
frame_duration_ms: int | None = None,
):
if mask is not None and not references:
raise ValueError("提供了蒙版但未提供参考图,请同时上传参考图")
@@ -295,6 +312,9 @@ async def _generate_gpt_images(
mask_tensor=mask,
output_format=output_format,
background=background,
**({"complexity": complexity} if complexity is not None else {}),
**({"frame_count": frame_count} if frame_count is not None else {}),
**({"frame_duration_ms": frame_duration_ms} if frame_duration_ms is not None else {}),
resize_mode=resize_mode,
special_price_parallel=False,
log_downloads=True,
@@ -542,7 +562,7 @@ class O1keyImageGenerator(io.ComfyNode):
io.Combo.Input(
"思考等级",
options=["低", "高"],
default="低",
default="高",
socketless=True,
),
io.Combo.Input(
@@ -566,6 +586,7 @@ class O1keyImageGenerator(io.ComfyNode):
),
io.Int.Input(
"seed",
display_name="种子",
default=0,
min=0,
max=0xFFFFFFFFFFFFFFFF,
@@ -587,7 +608,7 @@ class O1keyImageGenerator(io.ComfyNode):
),
io.Combo.Input(
"输出格式",
options=GPT_IMAGE_OUTPUT_FORMAT_OPTIONS,
options=GPT_IMAGE_26_OUTPUT_FORMAT_OPTIONS,
default="jpeg",
socketless=True,
),
@@ -600,7 +621,7 @@ class O1keyImageGenerator(io.ComfyNode):
io.Combo.Input(
"缩放图片",
options=["不缩放", "智能缩放"],
default="不缩放",
default="智能缩放",
tooltip="Nano Banana 与 GPT Image 生效;智能缩放可能发生像素偏移。",
socketless=True,
),
@@ -616,14 +637,19 @@ class O1keyImageGenerator(io.ComfyNode):
default=False,
label_on="开启",
label_off="关闭",
tooltip="关闭时保持普通参考图生成;开启后按素材图和目标图展开组合。",
tooltip="关闭时按普通参考图生成;开启后把素材图按所选模式与目标图组合,一次排队生成多张。",
socketless=True,
),
io.Combo.Input(
"批量模式",
options=list(IMAGE_BATCH_MODES),
default=IMAGE_BATCH_MODE_GROUP_TO_MODELS,
tooltip="整组素材:全部素材图作为一组并依次应用到多个目标;全匹配:每张素材图分别与每张目标图组合。",
tooltip=(
"素材图与目标图的配对方式。"
"整组素材→多个目标:整组素材作为一套,依次套用到每张目标图;"
"每张素材×每张目标:两两组合,覆盖最全;"
"每张素材单独出图:不需要目标图,每张素材各自生成。"
),
socketless=True,
),
io.String.Input(
@@ -659,13 +685,6 @@ class O1keyImageGenerator(io.ComfyNode):
tooltip="留空保存到 ComfyUI output 根目录;相对路径是 output 内的子文件夹;绝对路径可保存到任意磁盘目录。",
socketless=True,
),
io.Combo.Input(
"在线搜索",
options=["关闭", "打开"],
default="关闭",
tooltip="仅 Nano Banana 2 / 2.1 生效;打开时发送 google_search=true。",
socketless=True,
),
io.Boolean.Input(
"图层拆分",
default=False,
@@ -674,6 +693,31 @@ class O1keyImageGenerator(io.ComfyNode):
tooltip="仅 Seedream 生效;必须且只能上传1张参考图,返回底图和最多16个透明图层。",
socketless=True,
),
io.Combo.Input(
"复杂度", options=GPT_IMAGE_COMPLEXITY_OPTIONS, default="高",
tooltip="仅 GPT Image 2.6 生效;越高规划越充分、耗时越长。",
socketless=True,
),
io.Int.Input(
"帧数",
default=GPT_IMAGE_GIF_FRAME_COUNT_DEFAULT,
min=GPT_IMAGE_GIF_FRAME_COUNT_MIN,
max=GPT_IMAGE_GIF_FRAME_COUNT_MAX,
step=1,
display_mode=io.NumberDisplay.number,
tooltip="仅 GPT Image 2.6 且输出 GIF 时生效。",
socketless=True,
),
io.Int.Input(
"帧时长ms",
default=GPT_IMAGE_GIF_FRAME_DURATION_DEFAULT,
min=GPT_IMAGE_GIF_FRAME_DURATION_MIN,
max=GPT_IMAGE_GIF_FRAME_DURATION_MAX,
step=10,
display_mode=io.NumberDisplay.number,
tooltip="仅 GPT Image 2.6 且输出 GIF 时生效;按 10ms 取整。",
socketless=True,
),
],
outputs=[
io.Image.Output("IMAGE", display_name="IMAGE"),
@@ -690,7 +734,7 @@ class O1keyImageGenerator(io.ComfyNode):
prompt: str,
模型: str = "Nano Banana 2.1",
模型线路: str = "畅速",
思考等级: str = "低",
思考等级: str = "高",
分辨率: str = UNIFIED_IMAGE_SMART_RESOLUTION,
宽高比: str = "智能",
生图数量: str | int = "1",
@@ -708,8 +752,10 @@ class O1keyImageGenerator(io.ComfyNode):
filename_prefix: str = "o1key",
格式: str = "原始",
保存位置: str = "",
在线搜索: str = "关闭",
图层拆分: bool = False,
复杂度: str = "高",
帧数: int = GPT_IMAGE_GIF_FRAME_COUNT_DEFAULT,
帧时长ms: int = GPT_IMAGE_GIF_FRAME_DURATION_DEFAULT,
) -> io.NodeOutput:
layer_decomposition = _is_enabled(图层拆分)
if (not prompt or not prompt.strip()) and not (
@@ -719,7 +765,7 @@ class O1keyImageGenerator(io.ComfyNode):
if 输出格式 is None:
输出格式 = "png" if is_gpt_image_model(模型) else "jpeg"
if 缩放图片 is None:
缩放图片 = "智能缩放" if is_gpt_image_model(模型) else "不缩放"
缩放图片 = "智能缩放"
save_settings = _normalized_save_settings(
模型,
filename_prefix,
@@ -729,9 +775,8 @@ class O1keyImageGenerator(io.ComfyNode):
)
if 缩放图片 not in {"不缩放", "智能缩放"}:
raise ValueError("缩放图片参数无效")
if 在线搜索 not in {"关闭", "打开"}:
raise ValueError("在线搜索参数无效")
google_search = 模型 in {"Nano Banana 2.1", "Nano Banana 2"} and 在线搜索 == "打开"
# 在线搜索已下线:下游客户端仍支持 google_search,这里固定关闭。
google_search = False
image_count = int(生图数量)
if is_gpt_image_model(模型):
@@ -740,6 +785,8 @@ class O1keyImageGenerator(io.ComfyNode):
elif image_count not in UNIFIED_IMAGE_COUNTS:
raise ValueError("生图数量仅支持:1、2、4、9")
batch_enabled = _is_enabled(批量出图)
# Accept the pre-rename labels so workflows saved with them still run.
批量模式 = IMAGE_BATCH_MODE_ALIASES.get(批量模式, 批量模式)
if 批量模式 not in IMAGE_BATCH_MODES:
raise ValueError("批量模式无效")
@@ -874,13 +921,21 @@ class O1keyImageGenerator(io.ComfyNode):
raise ValueError("GPT Image 分辨率无效")
if 宽高比 not in GPT_IMAGE_ASPECT_RATIO_OPTIONS:
raise ValueError("GPT Image 宽高比无效")
complexity = resolve_gpt_image_complexity(模型, 复杂度)
resolve_gpt_image_quality(模型, 质量)
if 输出格式 not in GPT_IMAGE_OUTPUT_FORMAT_OPTIONS:
raise ValueError("GPT Image 输出格式无效")
输出格式 = resolve_gpt_image_output_format(模型, 输出格式)
if 背景 not in GPT_IMAGE_BACKGROUND_OPTIONS:
raise ValueError("GPT Image 背景参数无效")
if 背景 == "transparent" and 输出格式 == "jpeg":
if 背景 == "transparent" and 输出格式 not in {"png", "webp"}:
raise ValueError("GPT Image 透明背景仅支持 PNG 或 WebP 输出格式")
validate_gpt_image_vector_output(
模型,
输出格式,
has_images=bool(references) or bool(model_references),
has_mask=_parse_mask_manifest(蒙版清单) is not None,
)
frame_count = resolve_gpt_image_frame_count(输出格式, 帧数)
frame_duration_ms = resolve_gpt_image_frame_duration_ms(输出格式, 帧时长ms)
images_with_references: list[tuple[Image.Image, list[Any]]] = []
try:
images_with_references = await _generate_gpt_images(
@@ -897,6 +952,9 @@ class O1keyImageGenerator(io.ComfyNode):
resize_mode=缩放图片,
output_format=输出格式,
background=背景,
complexity=complexity,
frame_count=frame_count,
frame_duration_ms=frame_duration_ms,
)
except Exception as exc:
message = format_o1key_image_error(exc)
@@ -1009,18 +1067,27 @@ class O1keyImageSave(io.ComfyNode):
save_location=settings.get("save_location", ""),
naming_rule=settings.get("naming_rule", DEFAULT_SAVE_NAMING_RULE),
)
saved = ui.SavedImages([
ui.SavedResult(
item["filename"],
item["subfolder"],
(
io.FolderType.temp
if item.get("type") == "temp"
else io.FolderType.output
),
)
animated = any(
str(item.get("filename") or "").lower().endswith(".gif")
or item.get("media") == "gif"
or item.get("animated") is True
for item in descriptors
])
)
saved = ui.SavedImages(
[
ui.SavedResult(
item["filename"],
item["subfolder"],
(
io.FolderType.temp
if item.get("type") == "temp"
else io.FolderType.output
),
)
for item in descriptors
],
is_animated=animated,
)
return io.NodeOutput(images, ui=saved)