migrate PreviewImage node to V3

This commit is contained in:
bigcat88 2025-07-08 17:55:13 +03:00
parent 36770c1658
commit 1eb1a44883
No known key found for this signature in database
GPG Key ID: 1F0BF0EC3CF22721

View File

@ -1575,11 +1575,16 @@ class SaveImage(io.ComfyNodeV3):
is_output_node=True, is_output_node=True,
) )
@classmethod def __init__(self):
def execute(cls, images, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None): super().__init__()
full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path( self.output_dir = folder_paths.get_output_directory()
filename_prefix, folder_paths.get_output_directory(), images[0].shape[1], images[0].shape[0] self.type = "output"
) self.prefix_append = ""
self.compress_level = 4
def execute(self, images, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None):
filename_prefix += self.prefix_append
full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir, images[0].shape[1], images[0].shape[0])
results = list() results = list()
for (batch_number, image) in enumerate(images): for (batch_number, image) in enumerate(images):
i = 255. * image.cpu().numpy() i = 255. * image.cpu().numpy()
@ -1595,11 +1600,11 @@ class SaveImage(io.ComfyNodeV3):
filename_with_batch_num = filename.replace("%batch_num%", str(batch_number)) filename_with_batch_num = filename.replace("%batch_num%", str(batch_number))
file = f"{filename_with_batch_num}_{counter:05}_.png" file = f"{filename_with_batch_num}_{counter:05}_.png"
img.save(os.path.join(full_output_folder, file), pnginfo=metadata, compress_level=4) img.save(os.path.join(full_output_folder, file), pnginfo=metadata, compress_level=self.compress_level)
results.append({ results.append({
"filename": file, "filename": file,
"subfolder": subfolder, "subfolder": subfolder,
"type": "output", "type": self.type,
}) })
counter += 1 counter += 1
@ -1607,19 +1612,31 @@ class SaveImage(io.ComfyNodeV3):
class PreviewImage(SaveImage): class PreviewImage(SaveImage):
@classmethod
def DEFINE_SCHEMA(cls):
return io.SchemaV3(
node_id="PreviewImage",
display_name="Preview Image",
description="Preview the input images.",
category="image",
inputs=[
io.Image.Input(
"images",
display_name="images",
tooltip="The images to preview.",
),
],
hidden=[io.Hidden.prompt, io.Hidden.extra_pnginfo],
is_output_node=True,
)
def __init__(self): def __init__(self):
super().__init__()
self.output_dir = folder_paths.get_temp_directory() self.output_dir = folder_paths.get_temp_directory()
self.type = "temp" self.type = "temp"
self.prefix_append = "_temp_" + ''.join(random.choice("abcdefghijklmnopqrstupvxyz") for x in range(5)) self.prefix_append = "_temp_" + ''.join(random.choice("abcdefghijklmnopqrstupvxyz") for x in range(5))
self.compress_level = 1 self.compress_level = 1
@classmethod
def INPUT_TYPES(s):
return {"required":
{"images": ("IMAGE", ), },
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
}
class LoadImage(io.ComfyNodeV3): class LoadImage(io.ComfyNodeV3):
@classmethod @classmethod