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:
+88
-14
@@ -29,8 +29,22 @@ from ..utils.file_utils import (
|
||||
from ..utils.image_utils import parse_batch_prompts, pil_to_tensor, tensor_to_pil
|
||||
from ..utils.o1key_image_catalog import (
|
||||
GPT_IMAGE_BACKGROUND_OPTIONS,
|
||||
GPT_IMAGE_COMPLEXITY_OPTIONS,
|
||||
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,
|
||||
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_OUTPUT_FORMAT_OPTIONS,
|
||||
)
|
||||
from ..utils.gpt_image_media import animation_bytes_from_images, svg_bytes_from_image, write_bytes_atomic
|
||||
|
||||
try:
|
||||
from comfy.model_management import InterruptProcessingException
|
||||
@@ -134,14 +148,18 @@ class O1keyGPTImageBatch(io.ComfyNode):
|
||||
tooltip="可用独占一行的 --- 分隔多条提示词。"),
|
||||
io.Combo.Input(
|
||||
"模型", options=GPT_IMAGE_MODEL_OPTIONS,
|
||||
default="gpt-image-2.5-sunburst",
|
||||
default="gpt-image-2.6-sunburst",
|
||||
),
|
||||
io.Combo.Input("模型线路", options=GPT_IMAGE_ROUTE_OPTIONS, default="畅速"),
|
||||
io.Combo.Input(
|
||||
"复杂度", options=GPT_IMAGE_COMPLEXITY_OPTIONS, default="高",
|
||||
tooltip="仅 GPT Image 2.6 生效:低 / 中 / 高;越高规划越充分、耗时越长。",
|
||||
),
|
||||
io.Combo.Input("分辨率", options=_RESOLUTION_OPTIONS, default="智能"),
|
||||
io.Int.Input("生图数量", default=1, min=1, max=8, step=1),
|
||||
io.Combo.Input(
|
||||
"质量", options=GPT_IMAGE_25_QUALITY_OPTIONS, default="自动",
|
||||
tooltip="GPT Image 2.5 另支持超高=xhigh、最高=max。",
|
||||
tooltip="GPT Image 2.5 / 2.6 另支持超高=xhigh、最高=max。",
|
||||
),
|
||||
io.DynamicCombo.Input(
|
||||
"图片路径数量",
|
||||
@@ -151,7 +169,7 @@ class O1keyGPTImageBatch(io.ComfyNode):
|
||||
io.Mask.Input("遮罩", optional=True,
|
||||
tooltip="应用到每个任务的第一张参考图。"),
|
||||
references,
|
||||
io.Combo.Input("图片输出格式", options=["原始", "JPEG", "PNG", "WebP"],
|
||||
io.Combo.Input("图片输出格式", options=["原始", "JPEG", "PNG", "WebP", "SVG", "GIF"],
|
||||
default="原始"),
|
||||
io.Combo.Input(
|
||||
"背景",
|
||||
@@ -173,6 +191,24 @@ class O1keyGPTImageBatch(io.ComfyNode):
|
||||
"seed", default=0, min=0, max=2**31 - 1, step=1,
|
||||
control_after_generate=io.ControlAfterGenerate.randomize,
|
||||
),
|
||||
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="仅图片输出格式为 GIF 时生效。",
|
||||
),
|
||||
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="仅图片输出格式为 GIF 时生效;按 10ms 取整。",
|
||||
),
|
||||
],
|
||||
outputs=[io.Image.Output(display_name="输出图像")],
|
||||
accept_all_inputs=True,
|
||||
@@ -238,13 +274,33 @@ class O1keyGPTImageBatch(io.ComfyNode):
|
||||
naming_rule: str, task_index: int, base_filename: Optional[str],
|
||||
) -> List[str]:
|
||||
saved = []
|
||||
anim = animation_bytes_from_images(images)
|
||||
svg = svg_bytes_from_image(images[0]) if images else None
|
||||
if anim is not None or svg is not None:
|
||||
ext = ".gif" if anim is not None else ".svg"
|
||||
data = anim if anim is not None else svg
|
||||
if naming_rule == "自然数字":
|
||||
stem = str(task_index + 1)
|
||||
else:
|
||||
stem = base_filename or f"task_{task_index + 1}"
|
||||
path = os.path.join(folder, f"{stem}{ext}")
|
||||
collision = 1
|
||||
while os.path.exists(path):
|
||||
path = os.path.join(folder, f"{stem}+{collision}{ext}")
|
||||
collision += 1
|
||||
write_bytes_atomic(path, data)
|
||||
saved.append(path)
|
||||
if svg is not None:
|
||||
# also save raster preview frames/image next to svg
|
||||
pass
|
||||
return saved
|
||||
for image_index, image in enumerate(images, 1):
|
||||
if image_format == "原始":
|
||||
fmt = str(getattr(image, "format", None) or "PNG").upper()
|
||||
fmt = "JPEG" if fmt in ("JPG", "JPEG") else "WEBP" if fmt == "WEBP" else "PNG"
|
||||
else:
|
||||
fmt = image_format.upper()
|
||||
ext = {"JPEG": ".jpg", "WEBP": ".webp"}.get(fmt, ".png")
|
||||
ext = {"JPEG": ".jpg", "WEBP": ".webp", "GIF": ".gif", "SVG": ".svg"}.get(fmt, ".png")
|
||||
if naming_rule == "自然数字":
|
||||
stem = str(task_index + 1)
|
||||
if image_index > 1:
|
||||
@@ -284,7 +340,8 @@ class O1keyGPTImageBatch(io.ComfyNode):
|
||||
cls, client, pair, task_prompt, task_index, total_tasks,
|
||||
model, quality, size, image_count, seed, mask, output_format,
|
||||
background, resize_mode,
|
||||
folder, naming_rule, save_lock, progress_callback,
|
||||
folder, naming_rule, save_lock, progress_callback, complexity=None,
|
||||
frame_count=None, frame_duration_ms=None,
|
||||
) -> dict:
|
||||
try:
|
||||
task_started = time.time()
|
||||
@@ -294,6 +351,7 @@ class O1keyGPTImageBatch(io.ComfyNode):
|
||||
image_tensor=[pil_to_tensor([item.image]) for item in pair],
|
||||
mask_tensor=mask, output_format=output_format,
|
||||
background=background,
|
||||
**({"complexity": complexity} if complexity is not None else {}),
|
||||
progress_callback=progress_callback,
|
||||
special_price_parallel=True,
|
||||
log_downloads=True,
|
||||
@@ -328,7 +386,8 @@ class O1keyGPTImageBatch(io.ComfyNode):
|
||||
async def _process_async(
|
||||
cls, client, task_defs, model, quality, size, image_count, seed,
|
||||
mask, output_format, background, resize_mode,
|
||||
folder, naming_rule, pbar,
|
||||
folder, naming_rule, pbar, complexity=None,
|
||||
frame_count=None, frame_duration_ms=None,
|
||||
) -> List[dict]:
|
||||
total = len(task_defs)
|
||||
progress_values = [0] * total
|
||||
@@ -338,7 +397,8 @@ class O1keyGPTImageBatch(io.ComfyNode):
|
||||
client, pair, prompt, index, total, model, quality, size,
|
||||
image_count, seed, mask, output_format, background,
|
||||
resize_mode, folder, naming_rule,
|
||||
save_lock, cls._progress_callback(progress_values, index, pbar),
|
||||
save_lock, cls._progress_callback(progress_values, index, pbar), complexity,
|
||||
frame_count, frame_duration_ms,
|
||||
))
|
||||
for index, pair, prompt in task_defs
|
||||
]
|
||||
@@ -357,10 +417,11 @@ class O1keyGPTImageBatch(io.ComfyNode):
|
||||
|
||||
@classmethod
|
||||
def execute(
|
||||
cls, prompt, 模型="gpt-image-2.5-sunburst", 模型线路="畅速", 分辨率="智能", 生图数量=1,
|
||||
cls, prompt, 模型="gpt-image-2.6-sunburst", 模型线路="畅速", 分辨率="智能", 生图数量=1,
|
||||
质量="自动", 图片路径数量=None, 遮罩=None, seed=0,
|
||||
图片输出格式="原始", 图片保存命名规则="和原始图片名保持一致",
|
||||
图片保存路径="", 缩放图片="智能缩放", 背景="auto", **kwargs,
|
||||
图片保存路径="", 缩放图片="智能缩放", 背景="auto", 复杂度="高",
|
||||
帧数=GPT_IMAGE_GIF_FRAME_COUNT_DEFAULT, 帧时长ms=GPT_IMAGE_GIF_FRAME_DURATION_DEFAULT, **kwargs,
|
||||
) -> io.NodeOutput:
|
||||
if not prompt or not str(prompt).strip():
|
||||
raise ValueError("提示词不能为空")
|
||||
@@ -369,6 +430,7 @@ class O1keyGPTImageBatch(io.ComfyNode):
|
||||
if 背景 not in GPT_IMAGE_BACKGROUND_OPTIONS:
|
||||
raise ValueError("GPT Image 背景参数无效")
|
||||
|
||||
complexity = resolve_gpt_image_complexity(模型, 复杂度)
|
||||
actual_model = resolve_gpt_image_model(模型, 模型线路)
|
||||
|
||||
# 兼容旧节点通过命名参数调用时使用的字段名。
|
||||
@@ -419,11 +481,22 @@ class O1keyGPTImageBatch(io.ComfyNode):
|
||||
|
||||
folder = cls._output_folder(图片保存路径)
|
||||
quality = resolve_gpt_image_quality(模型, 质量)
|
||||
output_format = {"原始": "png", "JPEG": "jpeg", "PNG": "png", "WebP": "webp"}.get(图片输出格式, "png")
|
||||
if output_format not in GPT_IMAGE_OUTPUT_FORMAT_OPTIONS:
|
||||
raise ValueError("GPT Image 输出格式无效")
|
||||
if 背景 == "transparent" and output_format == "jpeg":
|
||||
output_format = {
|
||||
"原始": "png", "JPEG": "jpeg", "PNG": "png", "WebP": "webp",
|
||||
"SVG": "svg", "GIF": "gif",
|
||||
"jpeg": "jpeg", "png": "png", "webp": "webp", "svg": "svg", "gif": "gif",
|
||||
}.get(图片输出格式, "png")
|
||||
output_format = resolve_gpt_image_output_format(模型, output_format)
|
||||
if 背景 == "transparent" and output_format not in {"png", "webp"}:
|
||||
raise ValueError("GPT Image 透明背景仅支持 PNG 或 WebP 输出格式")
|
||||
frame_count = resolve_gpt_image_frame_count(output_format, 帧数)
|
||||
frame_duration_ms = resolve_gpt_image_frame_duration_ms(output_format, 帧时长ms)
|
||||
validate_gpt_image_vector_output(
|
||||
模型,
|
||||
output_format,
|
||||
has_images=True,
|
||||
has_mask=遮罩 is not None,
|
||||
)
|
||||
client = GptImageClient()
|
||||
client.base_url = get_base_url_by_route()
|
||||
client.response_log_enabled = False
|
||||
@@ -443,7 +516,8 @@ class O1keyGPTImageBatch(io.ComfyNode):
|
||||
client, task_defs, actual_model, quality, _resolve_size(分辨率),
|
||||
生图数量, seed, 遮罩, output_format, 背景,
|
||||
缩放图片, folder,
|
||||
图片保存命名规则, pbar,
|
||||
图片保存命名规则, pbar, complexity,
|
||||
frame_count, frame_duration_ms,
|
||||
)
|
||||
return loop.run_until_complete(client._run_with_interrupt(coro))
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user