From c38fa3753bf07e963d063dbb72eeea762230bd77 Mon Sep 17 00:00:00 2001 From: Martin Rizzo Date: Sat, 24 Jan 2026 20:09:03 -0300 Subject: [PATCH] fix: Correct parameter extraction in "Save Image" node This commit addresses a minor error in the "Save Image" node by ensuring that "steps", "sampler_name", and "scheduler" parameters are correctly extracted from nodes marked with ">>C". Additionally, it reorganizes the main code for parameter extraction and injection to improve readability and maintainability. --- nodes/save_image.py | 54 +-- .../save_image_experimental_tag.json | 310 +++++++++--------- 2 files changed, 189 insertions(+), 175 deletions(-) diff --git a/nodes/save_image.py b/nodes/save_image.py index 97959b4..b100db6 100644 --- a/nodes/save_image.py +++ b/nodes/save_image.py @@ -99,7 +99,7 @@ class SaveImage(io.ComfyNode): # attempt to inject CivitAI compatible metadata if civitai_compatible_metadata: - params = { "positive":"", "negative":"", "seed":-1, "steps":8, "cfg":1.0, "sampler_name":"", "scheduler_name":"" } + params = {} # try to find generation parameters from the initial sampler node, # initial sampler is defined as any sampler that is connected to an empty latent generator @@ -112,16 +112,19 @@ class SaveImage(io.ComfyNode): # if important parameters are found, inject all into the image's metadata, # this is done by creating new nodes that contain these parameters but are recognizable by CivitAI - found_params = params["positive"] or params["seed"]>=0 + found_params = ("positive" in params) or ("seed" in params) if found_params: prompt_nodes = cls.inject_civitai_nodes(prompt_nodes, - positive = params["positive"], - negative = params["negative"], - seed = params["seed"], - steps = params["steps"], - cfg = params["cfg"], - sampler_name = params["sampler_name"]) - + positive = params.get("positive" , "" ), + negative = params.get("negative" , "" ), + seed = params.get("seed" , 0 ), + steps = params.get("steps" , 50 ), + cfg = params.get("cfg" , 1.0 ), + sampler_name = params.get("sampler_name", "euler" ), + scheduler = params.get("scheduler" , "simple"), + width = params.get("width" , 1024 ), + height = params.get("height" , 1024 ), + ) # log the outcome of this metadata injection process to provide feedback if not found_params: logger.warning(f'"Save Image" was unable to locate generation parameters for injection as CivitAI metadata. Injection skipped.') @@ -567,7 +570,7 @@ class SaveImage(io.ComfyNode): if not params.get("positive" ): params.pop("positive" , None) if not params.get("negative" ): params.pop("negative" , None) if not params.get("sampler_name"): params.pop("sampler_name", None) - if not params.get("sheduler" ): params.pop("scheduler" , None) + if not params.get("scheduler" ): params.pop("scheduler" , None) if params.get("seed" ,-1) < 0 : params.pop("seed" , None) if params.get("steps",-1) < 1 : params.pop("steps" , None) if params.get("cfg" ,-1) < 0 : params.pop("cfg" , None) @@ -593,23 +596,32 @@ class SaveImage(io.ComfyNode): params = {} + prompt = get_input_string(node, "text", default="") + if prompt: + if "negative" in title.lower(): params["negative"] = prompt + else: params["positive"] = prompt + + seed = get_input_int(node, "seed", default=-1) + if seed>=0: params["seed"] = int(seed) + + steps = get_input_int(node, "steps", default=-1) + if steps>0: params["steps"] = int(steps) + + cfg = get_input_float(node, "cfg", default=-1.0) + if cfg>=0: params["cfg"] = float(cfg) + + sampler_name = get_input_string(node, "sampler_name", default="") + if sampler_name: params["sampler_name"] = sampler_name + + scheduler = get_input_string(node, "scheduler", default="") + if scheduler: params["scheduler"] = scheduler + width = get_input_int(node, "width", default=-1) if width>0: params["width"] = int(width) height = get_input_int(node, "height", default=-1) if height>0: params["height"] = int(height) - seed = get_input_int(node, "seed", default=-1) - if seed>=0: params["seed"] = int(seed) - - cfg = get_input_float(node, "cfg", default=-1.0) - if cfg>=0: params["cfg"] = float(cfg) - - prompt = get_input_string(node, "text", default="") - if prompt: - if "negative" in title.lower(): params["negative"] = prompt - else: params["positive"] = prompt - if params: contrib_count += 1 diff --git a/workflows/development/save_image_experimental_tag.json b/workflows/development/save_image_experimental_tag.json index 034b51b..1e5c84f 100644 --- a/workflows/development/save_image_experimental_tag.json +++ b/workflows/development/save_image_experimental_tag.json @@ -4,82 +4,6 @@ "last_node_id": 18, "last_link_id": 28, "nodes": [ - { - "id": 13, - "type": "KarrasScheduler", - "pos": [ - 480, - 1070 - ], - "size": [ - 270, - 130 - ], - "flags": {}, - "order": 0, - "mode": 0, - "inputs": [], - "outputs": [ - { - "name": "SIGMAS", - "type": "SIGMAS", - "links": [ - 15 - ] - } - ], - "properties": { - "Node name for S&R": "KarrasScheduler" - }, - "widgets_values": [ - 18, - 7, - 0.3, - 8 - ] - }, - { - "id": 6, - "type": "CLIPTextEncode", - "pos": [ - 330, - 240 - ], - "size": [ - 422.84503173828125, - 164.31304931640625 - ], - "flags": {}, - "order": 8, - "mode": 0, - "inputs": [ - { - "name": "clip", - "type": "CLIP", - "link": 23 - } - ], - "outputs": [ - { - "name": "CONDITIONING", - "type": "CONDITIONING", - "slot_index": 0, - "links": [ - 12 - ] - } - ], - "title": "Positive Prompt >>C", - "properties": { - "Node name for S&R": "CLIPTextEncode" - }, - "widgets_values": [ - "A viking soldier wearing viking armor, long hairs, in a battlefield with mud on his face, serious look, portrait shot, wide angle, professional photography, intricate details on his armor, selective focus" - ], - "color": "#232", - "bgcolor": "#353", - "shape": 1 - }, { "id": 15, "type": "Reroute", @@ -127,7 +51,7 @@ 110 ], "flags": {}, - "order": 1, + "order": 0, "mode": 0, "inputs": [], "outputs": [ @@ -186,79 +110,6 @@ "horizontal": false } }, - { - "id": 7, - "type": "CLIPTextEncode", - "pos": [ - 330, - 440 - ], - "size": [ - 420, - 110 - ], - "flags": {}, - "order": 9, - "mode": 0, - "inputs": [ - { - "name": "clip", - "type": "CLIP", - "link": 24 - } - ], - "outputs": [ - { - "name": "CONDITIONING", - "type": "CONDITIONING", - "slot_index": 0, - "links": [ - 13 - ] - } - ], - "title": "Negative Prompt >>C", - "properties": { - "Node name for S&R": "CLIPTextEncode" - }, - "widgets_values": [ - "(cartoon, painting, illustration:0.8), (worst quality, low quality, normal quality:1.8)" - ], - "color": "#322", - "bgcolor": "#533", - "shape": 1 - }, - { - "id": 12, - "type": "KSamplerSelect", - "pos": [ - 480, - 970 - ], - "size": [ - 270, - 58 - ], - "flags": {}, - "order": 2, - "mode": 0, - "inputs": [], - "outputs": [ - { - "name": "SAMPLER", - "type": "SAMPLER", - "links": [ - 14 - ] - } - ], - "properties": { - "Node name for S&R": "KSamplerSelect" - }, - "widgets_values": [ - "dpmpp_2m" - ] - }, { "id": 11, "type": "SamplerCustom", @@ -486,7 +337,7 @@ 98 ], "flags": {}, - "order": 3, + "order": 1, "mode": 0, "inputs": [], "outputs": [ @@ -556,6 +407,157 @@ "showOutputText": false, "horizontal": false } + }, + { + "id": 13, + "type": "KarrasScheduler", + "pos": [ + 480, + 70 + ], + "size": [ + 270, + 130 + ], + "flags": {}, + "order": 2, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "SIGMAS", + "type": "SIGMAS", + "links": [ + 15 + ] + } + ], + "title": "KarrasScheduler >>C", + "properties": { + "Node name for S&R": "KarrasScheduler" + }, + "widgets_values": [ + 18, + 7, + 0.3, + 8 + ] + }, + { + "id": 12, + "type": "KSamplerSelect", + "pos": [ + 480, + -30 + ], + "size": [ + 270, + 58 + ], + "flags": {}, + "order": 3, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "SAMPLER", + "type": "SAMPLER", + "links": [ + 14 + ] + } + ], + "title": "KSamplerSelect >>C", + "properties": { + "Node name for S&R": "KSamplerSelect" + }, + "widgets_values": [ + "dpmpp_2m" + ] + }, + { + "id": 6, + "type": "CLIPTextEncode", + "pos": [ + 330, + 240 + ], + "size": [ + 420, + 160 + ], + "flags": {}, + "order": 8, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 23 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "slot_index": 0, + "links": [ + 12 + ] + } + ], + "title": "Positive Prompt >>C", + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "A viking soldier wearing viking armor, long hairs, in a battlefield with mud on his face, serious look, portrait shot, wide angle, professional photography, intricate details on his armor, selective focus" + ], + "color": "#232", + "bgcolor": "#353", + "shape": 1 + }, + { + "id": 7, + "type": "CLIPTextEncode", + "pos": [ + 330, + 440 + ], + "size": [ + 420, + 110 + ], + "flags": {}, + "order": 9, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 24 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "slot_index": 0, + "links": [ + 13 + ] + } + ], + "title": "Negative Prompt >>C", + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "(cartoon, painting, illustration:0.8), (worst quality, low quality, normal quality:1.8)" + ], + "color": "#322", + "bgcolor": "#533", + "shape": 1 } ], "links": [ @@ -692,10 +694,10 @@ "config": {}, "extra": { "ds": { - "scale": 0.8264462809917354, + "scale": 0.9090909090909091, "offset": [ - 317.87600200896327, - 58.506300834537846 + 26.53997177921443, + 185.69008386997766 ] }, "frontendVersion": "1.35.9",