Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ def INPUT_TYPES(s):
input_dir = folder_paths.get_input_directory()
files = [f for f in os.listdir(input_dir) if os.path.isfile(os.path.join(input_dir, f))]
files = folder_paths.filter_files_content_types(files, ["image"])
return {"required":
{"image": (sorted(files), {"image_upload": True})},
return {"required": {
"image": (sorted(files), {"image_upload": True, "tooltip": "stick to input folder"})
},
"optional": {
"filename": ("STRING", {"default": "", "tooltip": "Single filename."}),
"is_from_output": ("BOOLEAN", {"default": False})
}
}

CATEGORY = "image"
Expand All @@ -24,8 +29,19 @@ def INPUT_TYPES(s):
RETURN_NAMES = ("image", "mask", "filename")
FUNCTION = "load_image"

def load_image(self, image):
image_path = folder_paths.get_annotated_filepath(image)

def _load_get_image_path(self, image, filename, is_from_output):
if filename == "":
filename = image_path = folder_paths.get_annotated_filepath(image)
else:
if is_from_output:
filename = folder_paths.get_output_directory() + '/' + filename
else:
filename = folder_paths.get_input_directory() + '/' + filename
return filename

def load_image(self, image, filename, is_from_output):
image_path = self._load_get_image_path(image, filename, is_from_output)

img = node_helpers.pillow(Image.open, image_path)

Expand Down Expand Up @@ -75,8 +91,8 @@ def load_image(self, image):
return (output_image, output_mask, filename)

@classmethod
def IS_CHANGED(s, image):
image_path = folder_paths.get_annotated_filepath(image)
def IS_CHANGED(s, image, filename, is_from_output):
image_path = s._load_get_image_path(image, filename, is_from_output)
m = hashlib.sha256()
with open(image_path, 'rb') as f:
m.update(f.read())
Expand All @@ -89,7 +105,6 @@ def VALIDATE_INPUTS(s, image):

return True


class LoadImageFolder:
@classmethod
def INPUT_TYPES(s):
Expand Down Expand Up @@ -308,7 +323,7 @@ def save_images(self, images, filenames="", filename_prefix="ComfyUI", prompt=No
file = f"{base_name}.png"
else:
# Use default naming
filename_with_batch_num = filename.replace("%batch_num%", str(batch_number))
filename_with_batch_num = filename.replace("%batch_num%", str(batch_number).zfill(4))
file = f"{filename_with_batch_num}_{counter:05}_.png"

img.save(os.path.join(full_output_folder, file), pnginfo=metadata, compress_level=self.compress_level)
Expand Down Expand Up @@ -338,7 +353,9 @@ def save_images(self, images, filenames="", filename_prefix="ComfyUI", prompt=No
file = f"{base_name}.png"

# Save to output directory
img.save(os.path.join(self.output_dir, file), pnginfo=metadata, compress_level=self.compress_level)
final_file_path = os.path.join(self.output_dir, file)
os.makedirs(os.path.dirname(final_file_path), exist_ok=True)
img.save(final_file_path, pnginfo=metadata, compress_level=self.compress_level)
results.append({
"filename": file,
"subfolder": "",
Expand Down