Add saveImage flag

This commit is contained in:
Sirshendu Ganguly
2026-02-02 13:59:39 -05:00
parent 0f57654db2
commit a67d78fde2
3 changed files with 24 additions and 17 deletions
+2 -2
View File
@@ -16,7 +16,7 @@ class RunwareSave3D:
"3dObject": ("STRING", {
"tooltip": "3D file URL from Runware 3D Inference node."
}),
"filename_prefix": ("STRING", {
"filenamePrefix": ("STRING", {
"default": "ComfyUI",
"tooltip": "Prefix for the filename."
}),
@@ -40,7 +40,7 @@ class RunwareSave3D:
def save_3d(self, **kwargs):
"""Save 3D file from URL"""
file_url = kwargs.get("3dObject", "")
filename_prefix = kwargs.get("filename_prefix", "ComfyUI")
filename_prefix = kwargs.get("filenamePrefix", "ComfyUI")
if not file_url or not file_url.strip():
raise Exception("No 3D URL provided. Please connect the '3dObject' output from Runware 3D Inference node.")
+21 -14
View File
@@ -14,10 +14,16 @@ class RunwareSaveImage:
"Images": ("STRING", {
"tooltip": "Image URL(s) from Runware Image Inference node. For multiple images, URLs should be comma-separated."
}),
"filename_prefix": ("STRING", {
"filenamePrefix": ("STRING", {
"default": "ComfyUI",
"tooltip": "Prefix for the filename."
}),
"saveImage": ("BOOLEAN", {
"default": True,
"label_on": "Enabled",
"label_off": "Disabled",
"tooltip": "If true, save to output folder. If false, download and preview only (purged when ComfyUI restarts)."
}),
}
}
@@ -26,12 +32,10 @@ class RunwareSaveImage:
OUTPUT_NODE = True
CATEGORY = "Runware"
def save_images(self, Images, filename_prefix="ComfyUI"):
def save_images(self, Images, **kwargs):
"""Save images using URL directly"""
# Get output directory
output_dir = folder_paths.get_output_directory()
os.makedirs(output_dir, exist_ok=True)
filename_prefix = kwargs.get("filenamePrefix", "ComfyUI")
save_image = kwargs.get("saveImage", True)
# Split URLs if comma-separated (for batch processing)
image_urls = [url.strip() for url in Images.split(",") if url.strip()]
@@ -39,37 +43,40 @@ class RunwareSaveImage:
if not image_urls:
raise Exception("No image added provided. Please connect the 'Image' from Runware Image Inference node.")
# Use output dir when saving, temp dir for preview only (purged on restart)
if save_image:
output_dir = folder_paths.get_output_directory()
os.makedirs(output_dir, exist_ok=True)
file_type = "output"
else:
output_dir = folder_paths.get_temp_directory()
file_type = "temp"
saved_files = []
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
# Process each image
for i, image_url in enumerate(image_urls):
# Download original file directly from URL to preserve quality
response = requests.get(image_url, timeout=30)
response.raise_for_status()
img_data = response.content
# Get extension from URL (handle query parameters)
url_without_params = image_url.split('?')[0]
extension = "." + url_without_params.split('.')[-1]
# Generate filename with timestamp
if len(image_urls) > 1:
filename = f"{filename_prefix}_{timestamp}_{i+1:03}.{extension.lstrip('.')}"
else:
filename = f"{filename_prefix}_{timestamp}.{extension.lstrip('.')}"
filepath = os.path.join(output_dir, filename)
# Write the downloaded file
with open(filepath, 'wb') as f:
f.write(img_data)
print(f"[Runware] Saved original file: {filepath}")
print(f"[Runware] {'Saved' if save_image else 'Preview'}: {filepath}")
# Add preview data for ComfyUI
saved_files.append({
"filename": filename,
"subfolder": "",
"type": "output"
"type": file_type
})
return {"ui": {"images": saved_files}}
File diff suppressed because one or more lines are too long