AI media harness for planning, generating, and editing locally
TypeScript
Match image export sizes to selected image
Bitti9f2dcf2596bd
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.mdindex 7c746e7..1f191d9 100644--- a/RELEASE_NOTES.md+++ b/RELEASE_NOTES.md@@ -32,6 +32,7 @@ This alpha update adds LAN generation workers, Linux support, expanded color gra## Fixes and improvements+- Image export offers sizes closest to the selected image's actual aspect ratio, even when project or saved generation settings differ.- Click a work queue job to open its image, scene, reference, generator download or export. Navigation works across projects and preserves unsaved project edits.- Character Sheet offers Debug prompt when debug options are enabled, exposing the separate compiled prompt for each of its four views.- Updated the bundled SlopFab runtime to API 1.18 for refmod export and support for version-5 refmod bundles.diff --git a/src/components/workspace/ImageExportView.test.tsx b/src/components/workspace/ImageExportView.test.tsxindex 976ca58..7ce477b 100644--- a/src/components/workspace/ImageExportView.test.tsx+++ b/src/components/workspace/ImageExportView.test.tsx@@ -66,16 +66,16 @@ it("sends the chosen size, format and JPG quality, and hides quality for PNG", a});it.each([- ["9:16", ["720 × 1280", "1080 × 1920", "1440 × 2560", "2160 × 3840"]],- ["1:1", ["512 × 512", "1024 × 1024", "1080 × 1080", "2048 × 2048", "4096 × 4096"]],- ["4:5", ["720 × 900", "1080 × 1350", "1440 × 1800", "2160 × 2700", "3072 × 3840"]],-] as const)("offers export sizes in the saved image's %s aspect ratio", (aspectRatio, labels) => {+ [768, 1376, ["720 × 1280", "1080 × 1920", "1440 × 2560", "2160 × 3840"]],+ [1056, 1024, ["512 × 512", "1024 × 1024", "1080 × 1080", "2048 × 2048", "4096 × 4096"]],+ [832, 1024, ["720 × 900", "1080 × 1350", "1440 × 1800", "2160 × 2700", "3072 × 3840"]],+] as const)("offers the closest presets for a %s × %s image despite different saved and project ratios", (width, height, labels) => {vi.spyOn(persistence, "readMediaFileUrl").mockResolvedValue(null);- const config = withOutput({ width: 1376, height: 768 });- config.assets[0].imageGeneration = { ...imageGenerationSnapshot(config, "", "test"), aspectRatio };+ const config = withOutput({ width, height });+ config.assets[0].imageGeneration = { ...imageGenerationSnapshot(config, "", "test"), aspectRatio: "16:9" };render(<ImageExportView config={config} folderPath="D:/Images" />);fireEvent.click(screen.getByRole("combobox", { name: "Resolution" }));- expect(screen.getAllByRole("option").map((option) => option.textContent)).toEqual(["1376 × 768 (original)", ...labels]);+ expect(screen.getAllByRole("option").map((option) => option.textContent)).toEqual([`${width} × ${height} (original)`, ...labels]);});it("keeps Original selected across images and omits duplicate presets", () => {@@ -99,15 +99,22 @@ it("shows the image bar and exports the image picked in it, leaving the Editor'svi.spyOn(persistence, "readMediaFileUrl").mockResolvedValue(null);vi.mocked(invoke).mockResolvedValue(true);const config = withOutput({ width: 2048, height: 1152 });- config.assets.push({ id: "second", name: "Second", kind: "image", relativePath: "media/generated/second.jpg", mimeType: "image/jpeg", width: 1024, height: 576, createdAt: config.createdAt } as ProjectConfig["assets"][number]);+ config.assets.push({ id: "second", name: "Second", kind: "image", relativePath: "media/generated/second.jpg", mimeType: "image/jpeg", width: 768, height: 1376, createdAt: config.createdAt } as ProjectConfig["assets"][number]);render(<ImageExportView config={config} folderPath="D:/Images" />);+ fireEvent.click(screen.getByRole("combobox", { name: "Resolution" }));+ fireEvent.click(screen.getByRole("option", { name: "1920 × 1080" }));const bar = screen.getByLabelText("Generated images");expect(within(bar).getByRole("button", { name: "View Out" })).toHaveAttribute("aria-pressed", "true");fireEvent.click(within(bar).getByRole("button", { name: "View Second" }));expect(within(bar).getByRole("button", { name: "View Second" })).toHaveAttribute("aria-pressed", "true");- expect(screen.getByRole("combobox", { name: "Resolution" })).toHaveTextContent("1024 × 576 (original)");+ expect(screen.getByRole("combobox", { name: "Resolution" })).toHaveTextContent("768 × 1376 (original)");+ fireEvent.click(screen.getByRole("combobox", { name: "Resolution" }));+ expect(screen.queryByRole("option", { name: "1920 × 1080" })).not.toBeInTheDocument();+ fireEvent.click(screen.getByRole("option", { name: "1080 × 1920" }));fireEvent.click(screen.getByRole("button", { name: "Export…" }));- await waitFor(() => expect(invoke).toHaveBeenCalledWith("export_generated_image", expect.objectContaining({ relativePath: "media/generated/second.jpg" })));+ await waitFor(() => expect(invoke).toHaveBeenCalledWith("export_generated_image", expect.objectContaining({+ relativePath: "media/generated/second.jpg", options: { format: "jpg", width: 1080, height: 1920, quality: 90 },+ })));expect(config.imageScene!.outputAssetId).toBe("out");});diff --git a/src/components/workspace/ImageExportView.tsx b/src/components/workspace/ImageExportView.tsxindex 5a01d79..6dea0d8 100644--- a/src/components/workspace/ImageExportView.tsx+++ b/src/components/workspace/ImageExportView.tsx@@ -1,6 +1,6 @@import { invoke } from "@tauri-apps/api/core";import { useState } from "react";-import { exportSizeChoices } from "../../lib/export";+import { closestExportAspectRatio, exportSizeChoices } from "../../lib/export";import type { ProjectConfig } from "../../lib/project";import { isTauri } from "../../lib/persistence";import { ComboBox, EmptyState, InfoBar, PropRow, PropSection, Slider, Splitter, tooltipProps, usePaneSize } from "../ui";@@ -52,10 +52,10 @@ export function ImageExportView({ config, folderPath }: { config: ProjectConfig;try { localStorage.setItem(STORAGE_KEY, JSON.stringify(next)); } catch { /* remembered for this session only */ }};- /* Generation sizes use a 32-pixel grid; exports use standard exact ratios.- A saved image retains its authored aspect even if project settings change. */+ /* Match presets to the selected image, including imported or resized images+ whose dimensions differ from their saved generation settings. */const original = output?.width && output?.height ? { width: output.width, height: output.height } : null;- const aspectRatio = output?.imageGeneration?.aspectRatio ?? config.settings.aspectRatio;+ const aspectRatio = original ? closestExportAspectRatio(original) : output?.imageGeneration?.aspectRatio ?? config.settings.aspectRatio;const sizes = exportSizeChoices(original, aspectRatio, "original").map((size, index) => original && index === 0 ? { ...size, value: "original" } : size);const [chosenSize, setChosenSize] = useState<string | null>(null);diff --git a/src/lib/export.ts b/src/lib/export.tsindex a0298c8..5660973 100644--- a/src/lib/export.ts+++ b/src/lib/export.ts@@ -235,6 +235,18 @@ export const STANDARD_EXPORT_SIZES: Record<AspectRatio, readonly (readonly [numbexport const exportSizeKey = (width: number, height: number) => `${width}x${height}`;+/** Compare proportional differences so portrait and landscape use the same scale. */+export function closestExportAspectRatio({ width, height }: { width: number; height: number }): AspectRatio {+ const ratio = width / height;+ return (Object.keys(STANDARD_EXPORT_SIZES) as AspectRatio[]).reduce((closest, candidate) => {+ const distance = (aspect: AspectRatio) => {+ const [w, h] = STANDARD_EXPORT_SIZES[aspect][0];+ return Math.abs(Math.log(ratio / (w / h)));+ };+ return distance(candidate) < distance(closest) ? candidate : closest;+ });+}+/** The Resolution choices of an export: `own` (the project's or the image's* size, named by `ownLabel`) first, then every standard size that differs. */export function exportSizeChoices(own: { width: number; height: number } | null, aspectRatio: AspectRatio, ownLabel: string) {