From 1408d125750070d914038ad73a6c3654bf9ef83b Mon Sep 17 00:00:00 2001 From: space-nuko <24979496+space-nuko@users.noreply.github.com> Date: Wed, 17 May 2023 20:33:59 -0500 Subject: [PATCH] Fix image upload --- src/lib/nodes/ComfyPickImageNode.ts | 10 +- src/lib/nodes/widgets/ComfyImageUploadNode.ts | 13 + .../nodes/widgets/ImageUploadWidget.svelte | 344 ------------------ src/lib/widgets/ImageUploadWidget.svelte | 14 +- 4 files changed, 21 insertions(+), 360 deletions(-) delete mode 100644 src/lib/nodes/widgets/ImageUploadWidget.svelte diff --git a/src/lib/nodes/ComfyPickImageNode.ts b/src/lib/nodes/ComfyPickImageNode.ts index 4e8de23..bc22e0f 100644 --- a/src/lib/nodes/ComfyPickImageNode.ts +++ b/src/lib/nodes/ComfyPickImageNode.ts @@ -48,16 +48,12 @@ export default class ComfyPickImageNode extends ComfyGraphNode { this._path = comfyFileToAnnotatedFilepath(this._image.comfyUIFile); this.filepathWidget.value = this._image.comfyUIFile.filename this.folderWidget.value = this._image.comfyUIFile.type - this.widthWidget.value = this._image.width - this.heightWidget.value = this._image.height } else { this._image = null; this._path = null; this.filepathWidget.value = "(None)" this.folderWidget.value = "" - this.widthWidget.value = 0 - this.heightWidget.value = 0 } console.log("SET", value, this._image, this._path) } @@ -72,12 +68,18 @@ export default class ComfyPickImageNode extends ComfyGraphNode { this.setOutputData(1, null) this.setOutputData(2, 0) this.setOutputData(3, 0) + + this.widthWidget.value = 0 + this.heightWidget.value = 0 } else { this.setOutputData(0, this._image); this.setOutputData(1, this._path); this.setOutputData(2, this._image.width); this.setOutputData(3, this._image.height); + + this.widthWidget.value = this._image.width + this.heightWidget.value = this._image.height } } } diff --git a/src/lib/nodes/widgets/ComfyImageUploadNode.ts b/src/lib/nodes/widgets/ComfyImageUploadNode.ts index ed25ade..de44ef0 100644 --- a/src/lib/nodes/widgets/ComfyImageUploadNode.ts +++ b/src/lib/nodes/widgets/ComfyImageUploadNode.ts @@ -5,6 +5,7 @@ import { BuiltInSlotType, LiteGraph, type SlotLayout } from "@litegraph-ts/core" import ImageUploadWidget from "$lib/widgets/ImageUploadWidget.svelte"; import type { ComfyWidgetProperties } from "./ComfyWidgetNode"; import ComfyWidgetNode from "./ComfyWidgetNode"; +import { get, writable, type Writable } from "svelte/store"; export interface ComfyImageUploadNodeProperties extends ComfyWidgetProperties { } @@ -31,10 +32,22 @@ export default class ComfyImageUploadNode extends ComfyWidgetNode = writable(0); + imgHeight: Writable = writable(0); + constructor(name?: string) { super(name, []) } + override onExecute() { + // TODO better way of getting image size? + const value = get(this.value) + if (value && value.length > 0) { + value[0].width = get(this.imgWidth) + value[0].height = get(this.imgHeight) + } + } + override parseValue(value: any): ComfyBoxImageMetadata[] { return parseWhateverIntoImageMetadata(value) || []; } diff --git a/src/lib/nodes/widgets/ImageUploadWidget.svelte b/src/lib/nodes/widgets/ImageUploadWidget.svelte deleted file mode 100644 index ef82b4b..0000000 --- a/src/lib/nodes/widgets/ImageUploadWidget.svelte +++ /dev/null @@ -1,344 +0,0 @@ - - -
- {#if widget.attrs.variant === "fileUpload" || isMobile} - - {:else} -
- - -
-
- -
-
-
-
- - -
- - - {#if !$nodeValue || $nodeValue.length === 0} - - - -
- -
- {#if uploadError} -
- Upload error: {uploadError} -
- {/if} -
- - - - -
- {:else} - - -
- -
- {#if uploadError} -
- Upload error: {uploadError} -
- {/if} -
- {/if} -
-
- {/if} -
- - diff --git a/src/lib/widgets/ImageUploadWidget.svelte b/src/lib/widgets/ImageUploadWidget.svelte index 8c71e30..1318211 100644 --- a/src/lib/widgets/ImageUploadWidget.svelte +++ b/src/lib/widgets/ImageUploadWidget.svelte @@ -28,23 +28,13 @@ $: console.warn("IMGSIZE2!!!", $imgWidth, $imgHeight) - $: if ($nodeValue && $nodeValue.length > 0) { - // TODO improve - if ($imgWidth > 0 && $imgHeight > 0) { - $nodeValue[0].width = $imgWidth - $nodeValue[0].height = $imgHeight - } - else { - $nodeValue[0].width = 0 - $nodeValue[0].height = 0 - } - } - function setNodeValue(widget: WidgetLayout) { if (widget) { node = widget.node as ComfyImageEditorNode nodeValue = node.value; attrsChanged = widget.attrsChanged; + imgWidth = node.imgWidth + imgHeight = node.imgHeight status = $nodeValue && $nodeValue.length > 0 ? "uploaded" : "empty" } };