diff --git a/__init__.py b/__init__.py index e5bb471..6b7b9f7 100644 --- a/__init__.py +++ b/__init__.py @@ -32,6 +32,15 @@ except Exception as e: _failed.append(("AugmentPNGToSVGPro", e)) print(f"[augment-vectorize] ⚠ AugmentPNGToSVGPro unavailable: {e}") +# ── Export SVG ── +try: + from .export_svg import AugmentExportSVG + NODE_CLASS_MAPPINGS["AugmentExportSVG"] = AugmentExportSVG + NODE_DISPLAY_NAME_MAPPINGS["AugmentExportSVG"] = "Export SVG" +except Exception as e: + _failed.append(("AugmentExportSVG", e)) + print(f"[augment-vectorize] ⚠ AugmentExportSVG unavailable: {e}") + # ── Summary ── WEB_DIRECTORY = "./web/js" __all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"] diff --git a/export_svg.py b/export_svg.py new file mode 100644 index 0000000..8fe1d2e --- /dev/null +++ b/export_svg.py @@ -0,0 +1,75 @@ +# "Design-focused node suite for ComfyUI." +# Copyright 2026 Augment Studio +# Augmentstudio.app + +import os +import json +import folder_paths + + +class AugmentExportSVG: + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "svg": ("AUGMENT_SVG",), + "filename_prefix": ("STRING", {"default": "svg/augment"}), + }, + "optional": { + "trigger": ("TRIGGER",), + }, + } + + RETURN_TYPES = ("TRIGGER") + RETURN_NAMES = ("trigger") + FUNCTION = "execute" + CATEGORY = "Augment/Enhance" + OUTPUT_NODE = True + + @classmethod + def VALIDATE_INPUTS(cls, **kwargs): + return True + + def execute(self, svg, filename_prefix="svg/export/asset", trigger=None): + output_dir = folder_paths.get_output_directory() + full_output_folder, filename, counter, subfolder, _ = ( + folder_paths.get_save_image_path(filename_prefix, output_dir) + ) + + os.makedirs(full_output_folder, exist_ok=True) + + file = f"{filename}_{counter:05}_.svg" + filepath = os.path.join(full_output_folder, file) + + if isinstance(svg, bytes): + svg_data = svg + elif isinstance(svg, str): + svg_data = svg.encode("utf-8") + else: + svg_data = bytes(svg) + + with open(filepath, "wb") as f: + f.write(svg_data) + + size = len(svg_data) + print(f"[Augment] Exported SVG ({size} bytes) to {filepath}") + + json_result = json.dumps({ + "node": "AugmentExportSVG", + "file": file, + "subfolder": subfolder, + "size_bytes": size, + }) + + return { + "ui": {"images": [{"filename": file, "subfolder": subfolder, "type": "output"}]}, + "result": (json_result, "done"), + } + + +NODE_CLASS_MAPPINGS = { + "AugmentExportSVG": AugmentExportSVG, +} +NODE_DISPLAY_NAME_MAPPINGS = { + "AugmentExportSVG": "Export SVG", +} diff --git a/png_to_svg_pro.py b/png_to_svg_pro.py index ddc2f69..96d5f53 100644 --- a/png_to_svg_pro.py +++ b/png_to_svg_pro.py @@ -28,7 +28,7 @@ class AugmentPNGToSVGPro: }, } - RETURN_TYPES = ("SVG", "AUGMENT_JSON", "TRIGGER") + RETURN_TYPES = ("AUGMENT_SVG", "AUGMENT_JSON", "TRIGGER") RETURN_NAMES = ("svg", "json_result", "trigger") FUNCTION = "execute" CATEGORY = "Augment/Enhance" @@ -106,13 +106,12 @@ class AugmentPNGToSVGPro: if svg_r.status_code != 200: raise RuntimeError(f"SVG fetch error: {svg_r.status_code}") - from comfy_api.latest._util.image_types import SVG - svg_bytes = io.BytesIO(svg_r.content) - size = svg_bytes.getbuffer().nbytes + svg_content = svg_r.content + size = len(svg_content) print(f"[Augment API] Done! Received SVG ({size} bytes)") json_result = json.dumps({"node": "PNGToSVGPro", "size_bytes": size}) - return {"ui": {"text": [svg_r.text[:500]]}, "result": (SVG([svg_bytes]), json_result, "done")} + return {"ui": {"text": [svg_r.text[:500]]}, "result": (svg_content, json_result, "done")} NODE_CLASS_MAPPINGS = { diff --git a/web/js/augment_style.js b/web/js/augment_style.js index 15c0314..fd0c90e 100644 --- a/web/js/augment_style.js +++ b/web/js/augment_style.js @@ -31,10 +31,11 @@ app.registerExtension({ window.open("https://augmentstudio.app/pricing", "_blank"); }); - const jsonIdx = this.outputs?.findIndex(o => o.name === "json_result"); - if (jsonIdx >= 0) { - this.outputs.splice(jsonIdx, 1); - } + this.outputs?.forEach(o => { + if (o.name === "json_result") { + o.hidden = true; + } + }); }; const origDraw = nodeType.prototype.onDrawForeground;