Image dimensions output for image upload widget

This commit is contained in:
space-nuko
2023-05-08 19:32:57 -05:00
parent 0f50dbae87
commit 92fbe1ea6b
5 changed files with 63 additions and 15 deletions

View File

@@ -37,8 +37,7 @@
};
let style: Styles = {
grid_cols: [4],
grid_rows: [4],
grid_cols: [3],
object_fit: "cover",
}
let element: HTMLDivElement;
@@ -125,11 +124,11 @@
}
</script>
{#if widget && node && nodeValue && $nodeValue != null}
{#if widget && node && nodeValue}
{#if widget.attrs.variant === "image"}
<div class="wrapper comfy-image-widget" style={widget.attrs.style || ""} bind:this={element}>
<Block variant="solid" padding={false}>
{#if $nodeValue.length > 0}
{#if $nodeValue && $nodeValue.length > 0}
<StaticImage
value={$nodeValue[$nodeValue.length-1].data}
show_label={widget.attrs.title != ""}

View File

@@ -9,6 +9,7 @@
import UploadText from "$lib/components/gradio/app/UploadText.svelte";
import { tick } from "svelte";
import notify from "$lib/notify";
import type { Vector2 } from "@litegraph-ts/core";
export let widget: WidgetLayout | null = null;
export let isMobile: boolean = false;
@@ -18,6 +19,9 @@
let dragging = false;
let pending_upload = false;
let old_value: Array<GradioFileData> | null = null;
let imgElem: HTMLImageElement | null = null
let imgWidth: number = 1;
let imgHeight: number = 1;
$: widget && setNodeValue(widget);
@@ -35,6 +39,18 @@
}
};
$: if (!(node && _value && _value.length > 0 && imgElem)) {
imgWidth = 1
imgHeight = 1
node.imageSize = [1, 1]
}
else if (imgWidth > 1 || imgHeight > 1) {
node.imageSize = [imgWidth, imgHeight]
}
else {
node.imageSize = [1, 1]
}
function onChange() {
console.warn("CHANGED", _value)
$nodeValue = _value || []
@@ -191,7 +207,12 @@
{#if _value && _value.length > 0 && !pending_upload}
{@const firstImage = _value[0]}
<ModifyUpload on:clear={handle_clear} absolute />
<img src={getImageUrl(firstImage)} alt={firstImage.orig_name} />
<img src={getImageUrl(firstImage)}
alt={firstImage.orig_name}
bind:this={imgElem}
bind:naturalWidth={imgWidth}
bind:naturalHeight={imgHeight}
/>
{:else}
<Upload
file_count={node.properties.fileCount}