Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Display generated images using saved dimensions

Bitti8329e722a6e0
diff --git a/src/components/workspace/ImageEditor.test.tsx b/src/components/workspace/ImageEditor.test.tsx
index 1e1c735..8e9ae36 100644
--- a/src/components/workspace/ImageEditor.test.tsx
+++ b/src/components/workspace/ImageEditor.test.tsx
@@ -20,6 +20,29 @@ function setup(initial = parseProjectConfig(fixture)) {
return () => latest;
}
+it("displays each generated image at its saved aspect ratio independently of future generation settings", () => {
+ const initial = parseProjectConfig(fixture);
+ initial.assets = [
+ { id: "wide", name: "Wide", kind: "image", relativePath: "media/generated/wide.jpg", mimeType: "image/jpeg", width: 1376, height: 768, createdAt: initial.createdAt },
+ { id: "tall", name: "Tall", kind: "image", relativePath: "media/generated/tall.jpg", mimeType: "image/jpeg", width: 1088, height: 1920, createdAt: initial.createdAt },
+ ];
+ initial.imageScene!.outputAssetId = "wide";
+ const current = setup(initial);
+ const frame = screen.getByLabelText("Image placement canvas").parentElement!;
+ expect(frame.style.getPropertyValue("--image-ratio")).toBe(String(1376 / 768));
+ fireEvent.change(screen.getByLabelText("Resolution"), { target: { value: "1344p" } });
+ fireEvent.change(screen.getByLabelText("Aspect ratio"), { target: { value: "1:1" } });
+ expect(current().settings).toMatchObject({ resolution: "1344p", aspectRatio: "1:1" });
+ expect(frame.style.getPropertyValue("--image-ratio")).toBe(String(1376 / 768));
+ fireEvent.click(screen.getByRole("button", { name: "View Tall" }));
+ expect(frame.style.getPropertyValue("--image-ratio")).toBe(String(1088 / 1920));
+ fireEvent.click(screen.getByRole("button", { name: "View Wide" }));
+ expect(frame.style.getPropertyValue("--image-ratio")).toBe(String(1376 / 768));
+ const reopened = parseProjectConfig(JSON.parse(JSON.stringify(current())));
+ expect(reopened.assets).toEqual(initial.assets);
+ expect(reopened.settings).toMatchObject({ resolution: "1344p", aspectRatio: "1:1" });
+});
+
it("removes generated images through their context menu and keeps the preview and thumbnail valid", () => {
const initial = parseProjectConfig(fixture);
initial.assets = ["First", "Second", "Third"].map((name) => ({ id: name, name, kind: "image", relativePath: `media/generated/${name}.jpg`, mimeType: "image/jpeg", createdAt: initial.createdAt }));
diff --git a/src/components/workspace/ImageEditor.tsx b/src/components/workspace/ImageEditor.tsx
index a4f4cba..37903c8 100644
--- a/src/components/workspace/ImageEditor.tsx
+++ b/src/components/workspace/ImageEditor.tsx
@@ -105,7 +105,11 @@ export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancel
element.addEventListener("wheel", wheel, { passive: false });
return () => element.removeEventListener("wheel", wheel);
}, [images.length]);
- const { width, height } = outputDimensions(config.settings.resolution, config.settings.aspectRatio);
+ // Generated assets retain the dimensions returned by the native encoder.
+ // Project settings size only the empty canvas and future generation requests.
+ const { width, height } = output?.width && output?.height
+ ? { width: output.width, height: output.height }
+ : outputDimensions(config.settings.resolution, config.settings.aspectRatio);
useEffect(() => subscribeGeneratorTemplates(() => setTemplates(loadGeneratorTemplateSettings())), []);
const commit = (next: ImageScene) => {
diff --git a/src/lib/workQueue.test.ts b/src/lib/workQueue.test.ts
index 795c834..c7b4a2c 100644
--- a/src/lib/workQueue.test.ts
+++ b/src/lib/workQueue.test.ts
@@ -100,17 +100,24 @@ describe("image generation work", () => {
const [request, config] = vi.mocked(enqueueSlopfabGeneration).mock.calls[0];
expect(request).toMatchObject({ stillImage: true, frames: 1, canvasWidth: 768, canvasHeight: 768 });
expect(config.providerSettings.slopfab.options.transformer).toBe("C:/h3.safetensors");
- session.update((current) => ({ ...current, imageScene: { ...current.imageScene!, background: "Edited during generation" } }));
+ session.update((current) => ({ ...current, settings: { ...current.settings, resolution: "1344p", aspectRatio: "1:1" }, imageScene: { ...current.imageScene!, background: "Edited during generation" } }));
await finish(queue, queue.getSnapshot().find((item) => item.kind === "image")!.id);
expect(invoke).toHaveBeenCalledWith("save_generated_image", { folderPath: "C:/Image", jobId: request.jobId });
const saved = session.getSnapshot().config;
expect(saved.imageScene?.background).toBe("Edited during generation");
expect(saved.imageScene?.outputAssetId).toBe(request.jobId);
expect(saved.assets[0]).toMatchObject({ kind: "image", mimeType: "image/jpeg", relativePath: "media/generated/still.jpg", width: 768, height: 768 });
+ expect(saved.settings.resolution).toBe("1344p");
expect(saved.generationJobs).toHaveLength(0);
expect(saveGeneratedScene).not.toHaveBeenCalled();
expect(releaseRendered).toHaveBeenCalledWith(request.jobId);
expect(parseProjectConfig(JSON.parse(JSON.stringify(saved))).imageScene).toEqual(saved.imageScene);
+ expect(parseProjectConfig(JSON.parse(JSON.stringify(saved))).assets[0]).toMatchObject({ width: 768, height: 768 });
+ queue.enqueueImage(session, template);
+ await waitFor(() => expect(enqueueSlopfabGeneration).toHaveBeenCalledTimes(2));
+ const nextRequest = vi.mocked(enqueueSlopfabGeneration).mock.calls[1][0];
+ expect(nextRequest).toMatchObject({ canvasWidth: 1344, canvasHeight: 1344 });
+ await queue.cancel(nextRequest.jobId);
});
it("serializes image and video work and allows cancellation before native submission", async () => {
const { queue, first } = setup(); const session = queue.project(imageProject());