AI media harness for planning, generating, and editing locally
TypeScript
Use standard image export resolutions
Bitti94fcbb84a892
diff --git a/src-tauri/src/tests/images.rs b/src-tauri/src/tests/images.rsindex ba86998..b56534b 100644--- a/src-tauri/src/tests/images.rs+++ b/src-tauri/src/tests/images.rs@@ -127,6 +127,13 @@ fn image_export_resizes_and_reencodes_at_the_chosen_quality() {let half = folder.path().join("half.png");export_image_file_with(&source, &half, ImageExportOptions { format: Some(ImageExportFormat::Png), width: Some(64), height: Some(40), quality: None }).unwrap();assert_eq!(::image::image_dimensions(&half).unwrap(), (64, 40));+ let enlarged = folder.path().join("enlarged.jpg");+ export_image_file_with(&source, &enlarged, ImageExportOptions { format: Some(ImageExportFormat::Jpg), width: Some(1280), height: Some(720), quality: Some(90) }).unwrap();+ let decoded = ::image::open(&enlarged).unwrap().to_rgb8();+ assert_eq!(decoded.dimensions(), (1280, 720));+ // Content fills the new canvas, including its far edge, rather than padding.+ assert!(decoded.get_pixel(1279, 719)[2] > 100);+ assert_eq!(fs::read(&source).unwrap(), original);let low = folder.path().join("low.jpg");export_image_file_with(&source, &low, ImageExportOptions { format: Some(ImageExportFormat::Jpg), width: None, height: None, quality: Some(20) }).unwrap();let low = fs::read(low).unwrap();diff --git a/src/components/workspace/ImageExportView.test.tsx b/src/components/workspace/ImageExportView.test.tsxindex 96763c7..976ca58 100644--- a/src/components/workspace/ImageExportView.test.tsx+++ b/src/components/workspace/ImageExportView.test.tsx@@ -7,6 +7,7 @@ import { parseProjectConfig, type ProjectConfig } from "../../lib/project";import * as persistence from "../../lib/persistence";import { invoke } from "@tauri-apps/api/core";import { ImageExportView } from "./ImageExportView";+import { imageGenerationSnapshot } from "../../lib/imageHistory";vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));afterEach(() => { cleanup(); localStorage.clear(); vi.restoreAllMocks(); });@@ -49,12 +50,14 @@ it("sends the chosen size, format and JPG quality, and hides quality for PNG", arender(<ImageExportView config={withOutput({ width: 2048, height: 1152 })} folderPath="D:/Images" />);fireEvent.change(screen.getByRole("slider", { name: "JPG quality" }), { target: { value: "60" } });fireEvent.click(screen.getByRole("combobox", { name: "Resolution" }));- expect(screen.getByRole("option", { name: "2720 × 1536" })).toBeInTheDocument();- fireEvent.click(screen.getByRole("option", { name: "3648 × 2048" }));+ expect(screen.getAllByRole("option").map((option) => option.textContent)).toEqual([+ "2048 × 1152 (original)", "1280 × 720", "1920 × 1080", "2560 × 1440", "3840 × 2160",+ ]);+ fireEvent.click(screen.getByRole("option", { name: "3840 × 2160" }));fireEvent.click(screen.getByRole("button", { name: "Export…" }));await waitFor(() => expect(invoke).toHaveBeenCalledWith("export_generated_image", {folderPath: "D:/Images", relativePath: "media/generated/out.png",- options: { format: "jpg", width: 3648, height: 2048, quality: 60 },+ options: { format: "jpg", width: 3840, height: 2160, quality: 60 },}));expect(JSON.parse(localStorage.getItem("slopus.image-export.v1")!)).toEqual({ format: "jpg", quality: 60 });fireEvent.click(screen.getByRole("combobox", { name: "Format" }));@@ -62,6 +65,35 @@ it("sends the chosen size, format and JPG quality, and hides quality for PNG", aexpect(screen.queryByRole("slider", { name: "JPG quality" })).toBeNull();});+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) => {+ vi.spyOn(persistence, "readMediaFileUrl").mockResolvedValue(null);+ const config = withOutput({ width: 1376, height: 768 });+ config.assets[0].imageGeneration = { ...imageGenerationSnapshot(config, "", "test"), aspectRatio };+ 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]);+});++it("keeps Original selected across images and omits duplicate presets", () => {+ vi.spyOn(persistence, "readMediaFileUrl").mockResolvedValue(null);+ const config = withOutput({ width: 1920, height: 1080 });+ config.assets.push({ ...config.assets[0], id: "second", name: "Second", width: 5760, height: 3240 });+ render(<ImageExportView config={config} folderPath="D:/Images" />);+ fireEvent.click(screen.getByRole("combobox", { name: "Resolution" }));+ expect(screen.queryByRole("option", { name: "1920 × 1080" })).not.toBeInTheDocument();+ fireEvent.click(screen.getByRole("option", { name: "1920 × 1080 (original)" }));+ fireEvent.click(screen.getByRole("button", { name: "View Second" }));+ expect(screen.getByRole("combobox", { name: "Resolution" })).toHaveTextContent("5760 × 3240 (original)");+ fireEvent.click(screen.getByRole("combobox", { name: "Resolution" }));+ expect(screen.getAllByRole("option").map((option) => option.textContent)).toEqual([+ "5760 × 3240 (original)", "1280 × 720", "1920 × 1080", "2560 × 1440", "3840 × 2160",+ ]);+});+it("shows the image bar and exports the image picked in it, leaving the Editor's image alone", async () => {vi.spyOn(persistence, "isTauri").mockReturnValue(true);vi.spyOn(persistence, "readMediaFileUrl").mockResolvedValue(null);diff --git a/src/components/workspace/ImageExportView.tsx b/src/components/workspace/ImageExportView.tsxindex 54b9364..f7c25d4 100644--- a/src/components/workspace/ImageExportView.tsx+++ b/src/components/workspace/ImageExportView.tsx@@ -1,7 +1,6 @@import { invoke } from "@tauri-apps/api/core";import { useState } from "react";-import { outputDimensions } from "../../lib/export";-import { IMAGE_RESOLUTIONS, type ProjectConfig } from "../../lib/project";+import type { AspectRatio, ProjectConfig } from "../../lib/project";import { isTauri } from "../../lib/persistence";import { ComboBox, EmptyState, InfoBar, PropRow, PropSection, Slider, Splitter, tooltipProps, usePaneSize } from "../ui";import { Image32 } from "../ui/icons";@@ -11,14 +10,21 @@ import { ReferenceImage } from "./ReferenceImage";/* The image project's Export tab: the same page as the video export (seeexport.css) — the image on the stage, filling it, and the resizable settingspane on the right opening straight on its first section, with Export… pinned- at its foot. Output sets the size (the image's own, or a rung of the project- ladder at its aspect), the format and, for JPG, the quality; Export… then+ at its foot. Output sets the size (the image's own, or a standard export size+ at its aspect), the format and, for JPG, the quality; Export… thenasks where to save. The image bar under the stage picks which image. Format and quality are remembered across projects. */type ImageFormat = "jpg" | "png";const STORAGE_KEY = "slopus.image-export.v1";const DEFAULT_QUALITY = 90;+const EXPORT_SIZES: Record<AspectRatio, readonly (readonly [number, number])[]> = {+ "16:9": [[1280, 720], [1920, 1080], [2560, 1440], [3840, 2160]],+ "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]],+};+function loadPreferences(): { format: ImageFormat; quality: number } {try {const saved = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? "{}") as { format?: unknown; quality?: unknown };@@ -53,17 +59,18 @@ export function ImageExportView({ config, folderPath }: { config: ProjectConfig;try { localStorage.setItem(STORAGE_KEY, JSON.stringify(next)); } catch { /* remembered for this session only */ }};- /* The image's own size first, then the image ladder at the project's aspect,- skipping a rung that matches the original. */+ /* Generation sizes use a 32-pixel grid; exports use standard exact ratios.+ A saved image retains its authored aspect even if project settings change. */const original = output?.width && output?.height ? { width: output.width, height: output.height } : null;+ const aspectRatio = output?.imageGeneration?.aspectRatio ?? config.settings.aspectRatio;const sizes = [- ...(original ? [{ ...original, label: `${original.width} × ${original.height} (original)` }] : []),- ...IMAGE_RESOLUTIONS.map((resolution) => outputDimensions(resolution, config.settings.aspectRatio))+ ...(original ? [{ ...original, value: "original", label: `${original.width} × ${original.height} (original)` }] : []),+ ...EXPORT_SIZES[aspectRatio].map(([width, height]) => ({ width, height })).filter((size) => !original || sizeKey(size.width, size.height) !== sizeKey(original.width, original.height))- .map((size) => ({ ...size, label: `${size.width} × ${size.height}` })),+ .map((size) => ({ ...size, value: sizeKey(size.width, size.height), label: `${size.width} × ${size.height}` })),];const [chosenSize, setChosenSize] = useState<string | null>(null);- const size = sizes.find((candidate) => sizeKey(candidate.width, candidate.height) === chosenSize) ?? sizes[0];+ const size = sizes.find((candidate) => candidate.value === chosenSize) ?? sizes[0];const exportImage = async () => {if (!output?.relativePath || disabled) return;@@ -103,11 +110,11 @@ export function ImageExportView({ config, folderPath }: { config: ProjectConfig;<PropRow label="Resolution" htmlFor="image-export-resolution"><ComboBoxid="image-export-resolution"- value={size ? sizeKey(size.width, size.height) : ""}+ value={size?.value ?? ""}disabled={exporting || sizes.length === 0}placeholder="Generate an image first"onChange={setChosenSize}- options={sizes.map((candidate) => ({ value: sizeKey(candidate.width, candidate.height), label: candidate.label }))}+ options={sizes.map((candidate) => ({ value: candidate.value, label: candidate.label }))}/></PropRow><PropRow label="Format" htmlFor="image-export-format">