Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Add imported image generation controls

Bitti87719843e6ae
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 744b91f..e821c6c 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -12,6 +12,7 @@ This alpha update adds Prompt video scenes, agent image drafts, Sol attention an
## Fixes and improvements
+- Imported still images now have steps, seed and resolution controls. Resolution defaults to the source dimensions rounded down to multiples of 32, with additional sizes matching the source aspect ratio.
- Fixed CUDA transformer-loading memory failures with bounded upload buffers, more accurate memory budgeting and automatic retries with more CPU offloading, while preserving precision and output settings.
- Agent chat retains earlier replies, corrections and errors throughout the conversation. Raw JSON and command payloads stay hidden; readable replies and summaries are shown.
- Zoom reduces visible extension seams by preventing grey canvas padding from affecting source encoding and widening the edge blend. Small source areas retain an unblended interior, and source transparency is retained.
diff --git a/src-tauri/src/commands/generation.rs b/src-tauri/src/commands/generation.rs
index 036357a..278f707 100644
--- a/src-tauri/src/commands/generation.rs
+++ b/src-tauri/src/commands/generation.rs
@@ -350,17 +350,64 @@ pub(crate) async fn export_reference_refmod(
fn prepare_image_edit_path(request: &mut slopfab::GenerationRequest, folder_path: Option<&str>) -> Result<(), String> {
if let Some(edit) = &request.image_edit {
+ if !(1..=8192).contains(&request.canvas_width) || !(1..=8192).contains(&request.canvas_height) {
+ return Err("Image edit dimensions must be between 1 and 8192 pixels.".into());
+ }
let root = crate::project::paths::ProjectRoot::open(folder_path.ok_or("Image edits require a project folder.")?)?;
- let path = root.existing(&edit.source_relative_path)?;
+ let mut path = root.existing(&edit.source_relative_path)?;
let (width, height) = ::image::image_dimensions(&path).map_err(|error| format!("Could not read source image: {error}"))?;
if width != request.canvas_width as u32 || height != request.canvas_height as u32 {
- return Err("Image edit dimensions do not match the source file.".into());
+ // Native inpainting takes its canvas dimensions from the source file.
+ // Prepare the selected size before planning or uploading to a LAN worker.
+ use std::hash::{Hash, Hasher};
+ let mut hash = std::collections::hash_map::DefaultHasher::new();
+ (&request.job_id, &path, request.canvas_width, request.canvas_height).hash(&mut hash);
+ let directory = root.directory("cache/image-edits")?;
+ let destination = directory.join(format!("{:016x}.png", hash.finish()));
+ let resized = ::image::open(&path).map_err(|error| format!("Could not read source image: {error}"))?
+ .resize_exact(request.canvas_width as u32, request.canvas_height as u32, ::image::imageops::FilterType::Lanczos3);
+ let mut temporary = tempfile::NamedTempFile::new_in(&directory).map_err(|error| error.to_string())?;
+ resized.write_to(&mut temporary, ::image::ImageFormat::Png).map_err(|error| error.to_string())?;
+ temporary.persist(&destination).map_err(|error| error.to_string())?;
+ path = destination;
}
request.image_edit_path = Some(path);
}
Ok(())
}
+#[cfg(test)]
+mod image_edit_tests {
+ use super::*;
+
+ #[test]
+ fn image_edit_prepares_selected_dimensions_without_changing_the_original() {
+ let folder = tempfile::tempdir().unwrap();
+ std::fs::write(folder.path().join("slopus.json"), "{}").unwrap();
+ let source = folder.path().join("source.png");
+ ::image::RgbaImage::from_pixel(101, 77, ::image::Rgba([80, 120, 160, 128])).save(&source).unwrap();
+ let original = std::fs::read(&source).unwrap();
+ let mut request: slopfab::GenerationRequest = serde_json::from_value(serde_json::json!({
+ "jobId":"edit-test", "prompt":"Warm up the lighting", "frames":1, "stillImage":true,
+ "steps":32, "seed":123456, "canvasWidth":96, "canvasHeight":64,
+ "imageEdit":{"sourceRelativePath":"source.png", "edits":[{"prompt":"Warm up the lighting", "x":0,"y":0,"width":96,"height":64}]}
+ })).unwrap();
+ for (width, height) in [(96, 64), (192, 128), (192, 128), (101, 77)] {
+ request.canvas_width = width;
+ request.canvas_height = height;
+ prepare_image_edit_path(&mut request, folder.path().to_str()).unwrap();
+ let prepared = ::image::open(request.image_edit_path.as_ref().unwrap()).unwrap().to_rgba8();
+ assert_eq!(prepared.dimensions(), (width as u32, height as u32));
+ assert_eq!(prepared.get_pixel(0, 0).0, [80, 120, 160, 128]);
+ assert_eq!(std::fs::read(&source).unwrap(), original);
+ }
+ request.canvas_width = -1;
+ assert!(prepare_image_edit_path(&mut request, folder.path().to_str()).is_err());
+ request.canvas_width = 8193;
+ assert!(prepare_image_edit_path(&mut request, folder.path().to_str()).is_err());
+ }
+}
+
#[tauri::command]
pub(crate) async fn cancel_slopfab_generation(
state: tauri::State<'_, slopfab::SlopfabRuntime>,
diff --git a/src-tauri/src/project/commands/images.rs b/src-tauri/src/project/commands/images.rs
index 797f52c..32d0d8b 100644
--- a/src-tauri/src/project/commands/images.rs
+++ b/src-tauri/src/project/commands/images.rs
@@ -25,6 +25,7 @@ pub(super) fn new_scene(prompt: &str) -> ImageScene {
ImageScene {
root_type: None,
source_image: None,
+ output_size: None,
nodes: vec![ImageNode {
id: "image-root".into(),
parent_id: None,
@@ -152,6 +153,7 @@ pub(super) fn apply(
scene = ImageScene {
root_type: scene.root_type,
source_image: scene.source_image,
+ output_size: scene.output_size,
nodes: nodes.clone(),
background: background.clone(),
style: style.clone(),
diff --git a/src-tauri/src/project/image.rs b/src-tauri/src/project/image.rs
index 5469698..7317b99 100644
--- a/src-tauri/src/project/image.rs
+++ b/src-tauri/src/project/image.rs
@@ -69,6 +69,8 @@ pub struct ImageScene {
pub root_type: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub source_image: Option<ImageSource>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub output_size: Option<ImageOutputSize>,
pub nodes: Vec<ImageNode>,
pub background: String,
pub style: ImageStyle,
@@ -86,6 +88,12 @@ pub struct ImageSource {
pub height: u32,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[serde(deny_unknown_fields)]
+pub struct ImageOutputSize {
+ pub width: u32,
+ pub height: u32,
+}
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct ImageNode {
pub id: String,
@@ -133,6 +141,10 @@ impl ImageScene {
}
pub fn validate(&self) -> Result<(), String> {
+ if self.output_size.as_ref().is_some_and(|size| [size.width, size.height].iter().any(|value|
+ !(32..=8192).contains(value) || value % 32 != 0)) {
+ return Err("Image output dimensions must be multiples of 32 between 32 and 8192 pixels.".into());
+ }
if self.root_type.as_deref().is_some_and(|kind| !matches!(kind, "prompt" | "image")) {
return Err("Invalid image root type.".into());
}
diff --git a/src-tauri/src/tests/images.rs b/src-tauri/src/tests/images.rs
index eeaef14..3666134 100644
--- a/src-tauri/src/tests/images.rs
+++ b/src-tauri/src/tests/images.rs
@@ -10,12 +10,14 @@ fn image_editing_draft_survives_save_and_reopen() {
let mut snapshot: serde_json::Value = serde_json::from_str(include_str!("../../../fixtures/image-generation-snapshot.json")).unwrap();
snapshot["scene"]["rootType"] = serde_json::json!("image");
snapshot["scene"]["sourceImage"] = serde_json::json!({"name":"Source", "relativePath":"media/imported/source.png", "width":65, "height":41});
+ snapshot["scene"]["outputSize"] = serde_json::json!({"width":128,"height":64});
config.assets.push(serde_json::from_value(serde_json::json!({
"id":"draft", "kind":"image", "name":"Editing Source", "relativePath":"media/imported/source.png", "mimeType":"image/png",
"width":65, "height":41, "createdAt":config.created_at, "imageDraft":true, "imageGeneration":snapshot
})).unwrap());
snapshot["scene"]["rootType"] = serde_json::json!("prompt");
snapshot["scene"]["sourceImage"] = serde_json::Value::Null;
+ snapshot["scene"].as_object_mut().unwrap().remove("outputSize");
snapshot["scene"]["nodes"].as_array_mut().unwrap().truncate(1);
snapshot["scene"]["nodes"][0]["description"] = serde_json::json!("");
config.assets.push(serde_json::from_value(serde_json::json!({
@@ -26,6 +28,9 @@ fn image_editing_draft_survives_save_and_reopen() {
let created = create_project_in(root.path(), &config).unwrap();
let opened = read_project(Path::new(&created.folder_path)).unwrap();
assert_eq!(opened.config.assets, config.assets);
+ let mut invalid_size = opened.config.clone();
+ invalid_size.assets[0].image_generation.as_mut().unwrap().scene.output_size.as_mut().unwrap().width = 127;
+ assert!(validate_and_normalize_config(invalid_size).is_err());
let mut invalid = opened.config;
invalid.assets[0].image_generation = None;
assert!(validate_and_normalize_config(invalid).is_err());
@@ -54,12 +59,13 @@ fn image_root_survives_save_and_agent_hierarchy_replacement() {
scene.style.mode = "none".into();
scene.root_type = Some("image".into());
scene.source_image = Some(crate::project::image::ImageSource { relative_path: "media/imported/source.png".into(), name: "Source".into(), width: 65, height: 41 });
+ scene.output_size = Some(crate::project::image::ImageOutputSize { width: 128, height: 64 });
let root = tempfile::tempdir().unwrap();
let created = create_project_in(root.path(), &config).unwrap();
let reopened = read_project(Path::new(&created.folder_path)).unwrap();
assert_eq!(reopened.config.image_scene, config.image_scene);
let mut command = serde_json::to_value(config.image_scene.as_ref().unwrap()).unwrap();
- for field in ["rootType", "sourceImage", "outputAssetId"] { command.as_object_mut().unwrap().remove(field); }
+ for field in ["rootType", "sourceImage", "outputAssetId", "outputSize"] { command.as_object_mut().unwrap().remove(field); }
command["op"] = serde_json::json!("image.set");
let parsed: ProjectCommand = serde_json::from_value(command).unwrap();
let changed = execute_commands_at(&config, &[parsed], &config.updated_at).unwrap();
diff --git a/src/components/workspace/ImageEditor.test.tsx b/src/components/workspace/ImageEditor.test.tsx
index ed5660c..0384521 100644
--- a/src/components/workspace/ImageEditor.test.tsx
+++ b/src/components/workspace/ImageEditor.test.tsx
@@ -108,6 +108,31 @@ it.each(["extend", "character-sheet"] as const)("returns from %s settings to nor
/* Undo lives in the title bar; inside the editor it is Ctrl+Z. */
const undoImageEdit = () => fireEvent.keyDown(screen.getByRole("tree", { name: "Image nodes" }), { key: "z", code: "KeyZ", ctrlKey: true });
+it("edits imported-image generation settings and restores them with the draft", () => {
+ const initial = parseProjectConfig(fixture);
+ initial.assets = [{ id: "imported", name: "Imported", kind: "image", relativePath: "media/source.png", mimeType: "image/png", width: 1001, height: 809, createdAt: initial.createdAt }];
+ const current = setup(initial);
+ fireEvent.click(screen.getByRole("button", { name: "View Imported" }));
+ expect(comboValue(screen.getByLabelText("Resolution"))).toBe("992x800");
+ typePrompt(screen.getByLabelText("Edit prompt"), "Warm up the lighting");
+ fireEvent.change(screen.getByLabelText("Steps"), { target: { value: "32" } });
+ fireEvent.change(screen.getByLabelText("Seed"), { target: { value: "123456" } });
+ choose("Resolution", "672 × 544");
+ expect(current().imageScene).toMatchObject({ steps: 32, seed: 123456, outputSize: { width: 672, height: 544 } });
+ expect(compileImageEdits(current()).edits[0]).toMatchObject({ width: 672, height: 544 });
+ expect(current().assets[0]).toMatchObject({ width: 1001, height: 809 });
+ const reopened = parseProjectConfig(JSON.parse(JSON.stringify(current())));
+ expect(reopened.imageScene).toEqual(current().imageScene);
+ fireEvent.click(screen.getByRole("button", { name: "View Imported" }));
+ expect(comboValue(screen.getByLabelText("Resolution"))).toBe("992x800");
+ fireEvent.click(screen.getByRole("button", { name: "View Editing Imported" }));
+ expect(screen.getByLabelText("Steps")).toHaveValue(32);
+ expect(screen.getByLabelText("Seed")).toHaveValue(123456);
+ expect(comboValue(screen.getByLabelText("Resolution"))).toBe("672x544");
+ choose("Resolution", "992 × 800");
+ expect(compileImageEdits(current()).edits[0]).toMatchObject({ width: 992, height: 800 });
+});
+
it.each(["media/photo.png", "references/photo.webp", "references/frames/frame.png"])("opens %s for editing after measuring its preview and preserves the original", async (relativePath) => {
vi.spyOn(persistence, "readMediaFileUrl").mockResolvedValue("blob:imported");
vi.stubGlobal("URL", class extends URL { static revokeObjectURL = vi.fn(); });
@@ -318,7 +343,7 @@ it("adds image files in edit mode and saves whole-image and drawn edits with sep
// References come from what each prompt cites; there is no list to tick.
expect(screen.queryByRole("checkbox", { name: "Mood" })).not.toBeInTheDocument();
typePrompt(screen.getByLabelText("Edit prompt"), "Make the lighting warmer like @[ref:Mood]");
- expect(compileImageEdits(current()).edits[0]).toMatchObject({ x: 0, y: 0, width: 1000, height: 800 });
+ expect(compileImageEdits(current()).edits[0]).toMatchObject({ x: 0, y: 0, width: 992, height: 800 });
const canvas = screen.getByLabelText("Image placement canvas");
Object.defineProperty(canvas, "setPointerCapture", { value: vi.fn() });
Object.defineProperty(canvas, "getBoundingClientRect", { value: () => ({ left: 0, top: 0, width: 1000, height: 800 }) });
diff --git a/src/components/workspace/ImageEditor.tsx b/src/components/workspace/ImageEditor.tsx
index 0b03ec2..57399c7 100644
--- a/src/components/workspace/ImageEditor.tsx
+++ b/src/components/workspace/ImageEditor.tsx
@@ -2,7 +2,7 @@ import { useEffect, useId, useMemo, useRef, useState, useSyncExternalStore, type
import { Add14, Add16, Boxes16, Boxes16Filled, ChevronDown14, ChevronRight14, Copy16, Cube16, Cube16Filled, Cursor16, Cursor16Filled, Delete14, Delete16, Edit16, Film16, FolderAdd16, FolderOpen16, Group16, Group16Filled, Image16, Image32, Paste16, References16, Rename16, Sparkle16, Stop14, Text16, Text16Filled } from "../ui/icons";
import { invoke } from "@tauri-apps/api/core";
import { addImageNode, createImageEditScene, createImageScene, duplicateImageNode, imageDescendants, imageScenePrompt, removeImageNode, resizeImageNode, type ImageBox, type ImageNode, type ImageScene, type ImageSource } from "../../lib/imageScene";
-import { compileImageEdits, editGeneratedImage, imageEditDebugPrompt } from "../../lib/imageEditing";
+import { compileImageEdits, editGeneratedImage, imageEditDebugPrompt, imageEditOutputSize, imageEditSize } from "../../lib/imageEditing";
import { imageSettings } from "../../lib/imageSettings";
import { outputDimensions } from "../../lib/export";
import { compileImagePrompt } from "../../lib/imagePrompt";
@@ -59,6 +59,13 @@ export function ImageEditor({ config, folderPath, onChange: changeConfig, onGene
const settings = imageSettings(config);
const root = scene.nodes.find((node) => node.kind === "root")!;
const imageRoot = scene.rootType === "image";
+ const editSize = imageRoot && scene.sourceImage ? imageEditOutputSize(scene) : null;
+ const sizeValue = (size: { width: number; height: number }) => `${size.width}x${size.height}`;
+ const editSizes = imageRoot && scene.sourceImage ? [...new Map([
+ imageEditSize(scene.sourceImage),
+ ...PROJECT_RESOLUTIONS.map((resolution) => imageEditSize(scene.sourceImage!, Number.parseInt(resolution))),
+ ...(editSize ? [editSize] : []),
+ ].filter((size) => size.width <= 8192 && size.height <= 8192).map((size) => [sizeValue(size), size])).values()] : [];
const generatedImage = config.assets.find((asset) => asset.id === scene.outputAssetId && !asset.imageDraft && asset.imageGeneration);
const recordedSeed = generatedImage?.imageGeneration?.usedSeed ?? generatedImage?.imageGeneration?.scene.seed;
const usedSeed = recordedSeed !== undefined && recordedSeed >= 0 ? recordedSeed : undefined;
@@ -721,16 +728,16 @@ export function ImageEditor({ config, folderPath, onChange: changeConfig, onGene
</>}
<div className="image-inspector__area"><span id={rootField("prompt-label")} tabIndex={selected.kind === "root" && imageRoot ? 0 : undefined} data-tooltip={selected.kind === "root" && imageRoot ? "Applies to the whole image before the individual edits." : undefined}>{promptLabel}</span><PromptTextField key={selected.id} aria-labelledby={rootField("prompt-label")} value={selected.description} references={promptReferences} missingLabel={missingReference} onChange={(description) => patchNode({ description })} /></div>
{selected.kind === "text" && <PropRow label="Text to render" htmlFor={rootField("text")}><input id={rootField("text")} className="text-field" value={selected.text} onChange={(event) => patchNode({ text: event.target.value })} /></PropRow>}
- {selected.kind === "root" && !imageRoot && <>
- <div className="image-inspector__area"><span id={rootField("background-label")}>Background (environment)</span><PromptTextField aria-labelledby={rootField("background-label")} rows={3} value={scene.background} references={promptReferences} missingLabel={missingReference} onChange={(background) => commit({ ...scene, background })} /></div>
+ {selected.kind === "root" && <>
+ {!imageRoot && <div className="image-inspector__area"><span id={rootField("background-label")}>Background (environment)</span><PromptTextField aria-labelledby={rootField("background-label")} rows={3} value={scene.background} references={promptReferences} missingLabel={missingReference} onChange={(background) => commit({ ...scene, background })} /></div>}
<PropSection title="Image generation" persistKey="image.generation" summary={`${generationStepsForTemplate(scene.steps, template)} steps`}>
<PropRow label="Steps" htmlFor={rootField("steps")}><input id={rootField("steps")} className="text-field" type="number" min="2" max="1000" value={scene.steps} onChange={(event) => { const value = Number(event.target.value); if (Number.isInteger(value) && value >= 2 && value <= 1000) commit({ ...scene, steps: value }); }} /></PropRow>
<PropRow label="Seed" htmlFor={rootField("seed")} tooltip="-1 picks a random seed"><input id={rootField("seed")} className="text-field" type="number" min="-1" max={Number.MAX_SAFE_INTEGER} value={scene.seed} onChange={(event) => { const value = Number(event.target.value); if (Number.isSafeInteger(value) && value >= -1) commit({ ...scene, seed: value }); }} /></PropRow>
{generatedImage && <UsedImageSeed id={rootField("used-seed")} seed={usedSeed} onError={setError} />}
- <PropRow label="Aspect ratio" htmlFor={rootField("ratio")}><ComboBox id={rootField("ratio")} aria-label="Aspect ratio" value={settings.aspectRatio} options={["16:9", "9:16", "1:1", "4:5"].map((ratio) => ({ value: ratio, label: ratio }))} onChange={(value) => { const aspectRatio = value as ProjectConfig["settings"]["aspectRatio"]; onChange((current) => ({ ...current, imageSettings: { ...imageSettings(current), aspectRatio } })); }} /></PropRow>
- <PropRow label="Resolution" htmlFor={rootField("resolution")}><ComboBox id={rootField("resolution")} aria-label="Resolution" value={settings.resolution} options={[...new Set([...PROJECT_RESOLUTIONS, settings.resolution])].map((resolution) => { const size = outputDimensions(resolution, settings.aspectRatio); return { value: resolution, label: `${size.width} × ${size.height}` }; })} onChange={(value) => { const resolution = value as ProjectConfig["settings"]["resolution"]; onChange((current) => ({ ...current, imageSettings: { ...imageSettings(current), resolution } })); }} /></PropRow>
+ {!imageRoot && <PropRow label="Aspect ratio" htmlFor={rootField("ratio")}><ComboBox id={rootField("ratio")} aria-label="Aspect ratio" value={settings.aspectRatio} options={["16:9", "9:16", "1:1", "4:5"].map((ratio) => ({ value: ratio, label: ratio }))} onChange={(value) => { const aspectRatio = value as ProjectConfig["settings"]["aspectRatio"]; onChange((current) => ({ ...current, imageSettings: { ...imageSettings(current), aspectRatio } })); }} /></PropRow>}
+ {imageRoot ? editSize && <PropRow label="Resolution" htmlFor={rootField("resolution")}><ComboBox id={rootField("resolution")} aria-label="Resolution" value={sizeValue(editSize)} options={editSizes.map((size) => ({ value: sizeValue(size), label: `${size.width} × ${size.height}` }))} onChange={(value) => { const size = editSizes.find((size) => sizeValue(size) === value); if (size) commit({ ...scene, outputSize: size }); }} /></PropRow> : <PropRow label="Resolution" htmlFor={rootField("resolution")}><ComboBox id={rootField("resolution")} aria-label="Resolution" value={settings.resolution} options={[...new Set([...PROJECT_RESOLUTIONS, settings.resolution])].map((resolution) => { const size = outputDimensions(resolution, settings.aspectRatio); return { value: resolution, label: `${size.width} × ${size.height}` }; })} onChange={(value) => { const resolution = value as ProjectConfig["settings"]["resolution"]; onChange((current) => ({ ...current, imageSettings: { ...imageSettings(current), resolution } })); }} /></PropRow>}
</PropSection>
- <PropSection title="Style" persistKey="image.style">
+ {!imageRoot && <PropSection title="Style" persistKey="image.style">
<PropRow label="Mode" htmlFor={rootField("mode")}><ComboBox id={rootField("mode")} aria-label="Mode" value={scene.style.mode} options={[{ value: "none", label: "None" }, { value: "photo", label: "Photo" }, { value: "art", label: "Art" }]} onChange={(value) => commit({ ...scene, style: { ...scene.style, mode: value as "none" | "photo" | "art" } })} /></PropRow>
{scene.style.mode !== "none" && <>
<TagEditor label="Aesthetics" value={scene.style.aesthetics} suggestions={scene.style.mode === "photo" ? styleSuggestions.PhotoAestheticsSuggestions : styleSuggestions.ArtAestheticsSuggestions} onChange={(aesthetics) => commit({ ...scene, style: { ...scene.style, aesthetics } })} />
@@ -738,11 +745,8 @@ export function ImageEditor({ config, folderPath, onChange: changeConfig, onGene
{scene.style.mode === "art" && <TagEditor label="Medium" value={scene.style.medium} suggestions={styleSuggestions.MediumSuggestions} onChange={(medium) => commit({ ...scene, style: { ...scene.style, medium } })} />}
<TagEditor key={scene.style.mode} label={scene.style.mode === "photo" ? "Camera / lens" : "Art style"} value={scene.style.detail} suggestions={scene.style.mode === "photo" ? styleSuggestions.PhotoSuggestions : styleSuggestions.ArtSuggestions} onChange={(detail) => commit({ ...scene, style: { ...scene.style, detail } })} />
</>}
- </PropSection>
+ </PropSection>}
</>}
- {selected.kind === "root" && imageRoot && generatedImage && <PropSection title="Image generation" persistKey="image.generation">
- <UsedImageSeed id={rootField("used-seed")} seed={usedSeed} onError={setError} />
- </PropSection>}
{!isMiniMaxH3 && selected.kind !== "root" && <PropSection title="Placement (0–1000)" persistKey="image.placement">
<label className="image-check"><input type="checkbox" checked={Boolean(selected.box)} onChange={(event) => patchNode({ box: event.target.checked ? { x: 250, y: 250, width: 500, height: 500 } : null })} />Explicit placement</label>
{selected.box && (["x", "y", "width", "height"] as const).map((field) => <PropRow key={field} label={field === "x" ? "X" : field === "y" ? "Y" : field === "width" ? "Width" : "Height"} htmlFor={rootField(field)}>
diff --git a/src/lib/imageCommands.ts b/src/lib/imageCommands.ts
index afd893d..d627844 100644
--- a/src/lib/imageCommands.ts
+++ b/src/lib/imageCommands.ts
@@ -4,7 +4,7 @@ import { imageDescendants, imageNodeSchema, imageSceneSchema, removeImageNode, r
const id = z.string().min(1);
const before = id.nullish();
const editableNode = imageNodeSchema.pick({ name: true, description: true, text: true, box: true, colors: true, referenceIds: true }).partial();
-const authoredScene = imageSceneSchema.innerType().omit({ outputAssetId: true, rootType: true, sourceImage: true });
+const authoredScene = imageSceneSchema.innerType().omit({ outputAssetId: true, rootType: true, sourceImage: true, outputSize: true });
const configuration = authoredScene.omit({ nodes: true, style: true }).partial().extend({ prompt: z.string().optional(), style: authoredScene.shape.style.partial().strict().optional() });
export const imageCommandSchema = z.discriminatedUnion("op", [
authoredScene.extend({ op: z.literal("image.set") }).strict(),
diff --git a/src/lib/imageEditing.test.ts b/src/lib/imageEditing.test.ts
index e403eac..4b0085a 100644
--- a/src/lib/imageEditing.test.ts
+++ b/src/lib/imageEditing.test.ts
@@ -1,10 +1,27 @@
import { expect, it } from "vitest";
import { parseProjectConfig } from "./project";
import { addImageNode, createImageEditScene } from "./imageScene";
-import { compileImageEdits, editGeneratedImage } from "./imageEditing";
+import { compileImageEdits, editGeneratedImage, imageEditSize } from "./imageEditing";
import fixture from "../../fixtures/project-v1-image.json";
-it("uses hierarchy order, skips empty groups, and converts boxes to original pixels", () => {
+it.each([
+ [1001, 809, 992, 800], [809, 1001, 800, 992], [640, 480, 640, 480], [17, 31, 32, 32],
+])("aligns a %i × %i source to %i × %i", (width, height, expectedWidth, expectedHeight) => {
+ expect(imageEditSize({ width, height })).toEqual({ width: expectedWidth, height: expectedHeight });
+});
+
+it("scales local edits to the selected output size and validates saved dimensions", () => {
+ const config = parseProjectConfig(fixture);
+ config.imageScene = addImageNode(createImageEditScene({ relativePath: "media/source.png", name: "Source", width: 1001, height: 809 }), "image-root", "object", { x: 750, y: 750, width: 250, height: 250 });
+ config.imageScene.nodes[1].description = "Add a balloon";
+ config.imageScene.outputSize = { width: 672, height: 544 };
+ expect(compileImageEdits(config).edits[0]).toMatchObject({ x: 504, y: 408, width: 168, height: 136 });
+ expect(parseProjectConfig(JSON.parse(JSON.stringify(config))).imageScene).toEqual(config.imageScene);
+ config.imageScene.outputSize.width = 673;
+ expect(() => parseProjectConfig(config)).toThrow();
+});
+
+it("uses hierarchy order, skips empty groups, and converts boxes to the rounded output dimensions", () => {
const config = parseProjectConfig(fixture);
let scene = createImageEditScene({ relativePath: "media/imported/source.png", name: "Source", width: 101, height: 77 });
scene = addImageNode(scene, "image-root", "group");
@@ -18,10 +35,10 @@ it("uses hierarchy order, skips empty groups, and converts boxes to original pix
config.settings.defaultLook = "watercolor";
const { edits } = compileImageEdits(config);
expect(edits).toHaveLength(2);
- expect(edits[0]).toMatchObject({ x: 90, y: 69, width: 11, height: 8 });
+ expect(edits[0]).toMatchObject({ x: 86, y: 57, width: 10, height: 7 });
expect(edits[0].prompt).toContain("A red balloon");
expect(edits[0].prompt).not.toMatch(/Use these colors|#FF0000/);
- expect(edits[1]).toMatchObject({ x: 25, y: 19, width: 51, height: 39 });
+ expect(edits[1]).toMatchObject({ x: 24, y: 16, width: 48, height: 32 });
expect(edits[1].prompt).toContain("A blue boat");
expect(edits[0].prompt).not.toContain("watercolor");
expect(edits[0].prompt).toContain("[Shot 1]");
@@ -79,7 +96,7 @@ it("applies whole-image actions first and compiles only the references each edit
config.imageScene = addImageNode(config.imageScene, root.id, "object");
Object.assign(config.imageScene.nodes[1], { description: "Add a @[ref:Balloon]" });
let edits = compileImageEdits(config).edits;
- expect(edits[0]).toMatchObject({ x: 0, y: 0, width: 101, height: 77 });
+ expect(edits[0]).toMatchObject({ x: 0, y: 0, width: 96, height: 64 });
expect(edits[0].prompt).toContain("Warm up the entire image like <Subject 1>");
expect(edits[0].prompt).toContain("<Subject 1> is Lighting, providing appearance from <Picture 2>");
expect(edits[0].prompt).not.toContain("Balloon");
diff --git a/src/lib/imageEditing.ts b/src/lib/imageEditing.ts
index 8b570ae..fcd8099 100644
--- a/src/lib/imageEditing.ts
+++ b/src/lib/imageEditing.ts
@@ -1,5 +1,5 @@
import { imageSettings } from "./imageSettings";
-import { createImageEditScene, createImageScene, imageSourceSchema, type ImageNode, type ImageSource } from "./imageScene";
+import { createImageEditScene, createImageScene, imageSourceSchema, type ImageNode, type ImageScene, type ImageSource } from "./imageScene";
import { compileImagePrompt } from "./imagePrompt";
import type { ProjectConfig, ProjectReference } from "./project";
@@ -17,10 +17,20 @@ export interface ImageEditStep {
refmods?: Array<{ path: string; strength: number; copies: number }>;
}
export const imageEditDebugPrompt = (edits: ImageEditStep[]) => edits.map((edit, index) => `Edit ${index + 1} (${edit.x}, ${edit.y}, ${edit.width}, ${edit.height})\n${edit.prompt}`).join("\n\n");
+/** Imported images default to their own dimensions, rounded down to the model grid. */
+export function imageEditSize(source: Pick<ImageSource, "width" | "height">, shortEdge = Math.min(source.width, source.height)) {
+ const scale = shortEdge / Math.min(source.width, source.height);
+ const align = (value: number) => Math.max(32, Math.floor(value / 32) * 32);
+ return { width: align(source.width * scale), height: align(source.height * scale) };
+}
+export function imageEditOutputSize(scene: ImageScene) {
+ return scene.outputSize ?? imageEditSize(scene.sourceImage!);
+}
export function compileImageEdits(config: ProjectConfig): { source: ImageSource; edits: (ImageEditStep & { references: ProjectReference[] })[] } {
const scene = config.imageScene!;
const source = scene.sourceImage;
if (!source) throw new Error("Open an image before adding edits.");
+ const size = imageEditOutputSize(scene);
const root = scene.nodes.find((node) => node.kind === "root")!;
// The root describes a whole-image edit, followed by the local edits in order.
const ordered: ImageNode[] = root.description.trim() ? [{ ...root, box: { x: 0, y: 0, width: 1000, height: 1000 } }] : [];
@@ -29,10 +39,10 @@ export function compileImageEdits(config: ProjectConfig): { source: ImageSource;
const edits = ordered.filter((node) => node.kind !== "group" || node.description.trim() || node.text).map((node) => {
if (!node.box) throw new Error(`Set a placement box for '${node.name}'.`);
if (!node.description.trim() && !node.text) throw new Error(`Describe the edit for '${node.name}'.`);
- const x = Math.min(source.width - 1, Math.floor(node.box.x * source.width / 1000));
- const y = Math.min(source.height - 1, Math.floor(node.box.y * source.height / 1000));
- const right = Math.min(source.width, Math.ceil((node.box.x + node.box.width) * source.width / 1000));
- const bottom = Math.min(source.height, Math.ceil((node.box.y + node.box.height) * source.height / 1000));
+ const x = Math.min(size.width - 1, Math.floor(node.box.x * size.width / 1000));
+ const y = Math.min(size.height - 1, Math.floor(node.box.y * size.height / 1000));
+ const right = Math.min(size.width, Math.ceil((node.box.x + node.box.width) * size.width / 1000));
+ const bottom = Math.min(size.height, Math.ceil((node.box.y + node.box.height) * size.height / 1000));
const description = ["The edited keyframe corresponds to <Picture 1> with the following change. Preserve the composition and any previously completed edits.", node.description,
node.text ? `Render the exact text "${node.text}".` : ""].filter(Boolean).join(" ");
const editScene = { ...createImageScene(description), rootType: "image" as const, sourceImage: source, referenceIds: [] };
diff --git a/src/lib/imageScene.ts b/src/lib/imageScene.ts
index 7d12063..3290107 100644
--- a/src/lib/imageScene.ts
+++ b/src/lib/imageScene.ts
@@ -17,6 +17,7 @@ export type ImageSource = z.infer<typeof imageSourceSchema>;
export const imageSceneSchema = z.object({
rootType: z.enum(["prompt", "image"]).optional(),
sourceImage: imageSourceSchema.nullish(),
+ outputSize: z.object({ width: z.number().int().min(32).max(8192).multipleOf(32), height: z.number().int().min(32).max(8192).multipleOf(32) }).optional(),
nodes: z.array(imageNodeSchema).min(1).max(500),
background: z.string(),
style: z.object({ mode: z.enum(["none", "photo", "art"]), aesthetics: z.string(), lighting: z.string(), medium: z.string(), detail: z.string() }),
diff --git a/src/lib/workQueue.test.ts b/src/lib/workQueue.test.ts
index 1403b61..9384ac5 100644
--- a/src/lib/workQueue.test.ts
+++ b/src/lib/workQueue.test.ts
@@ -463,7 +463,7 @@ describe("image generation work", () => {
const request = vi.mocked(enqueueSlopfabGeneration).mock.calls[0][0];
const steps = request.imageEdit!.edits;
expect(steps).toHaveLength(2);
- expect(steps[0]).toMatchObject({ x: 0, y: 0, width: 101, height: 77 });
+ expect(steps[0]).toMatchObject({ x: 0, y: 0, width: 96, height: 64 });
for (const [index, name] of ["Lighting", "Balloon"].entries()) {
expect(steps[index].referencePaths).toEqual(["C:/Image/media/generated/source.jpg", `C:/Image/references/${name}.png`]);
expect(steps[index].refmods).toEqual([{ path: `C:/Image/references/${name}.safetensors`, strength: 0.75, copies: 2 }]);
@@ -501,9 +501,9 @@ describe("image generation work", () => {
}
const draftId = session.getSnapshot().config.imageScene!.outputAssetId!;
expect(session.getSnapshot().config.assets[0]).toMatchObject({ id: draftId, imageDraft: true });
- expect(request).toMatchObject({ stillImage: true, frames: 1, canvasWidth: 101, canvasHeight: 77, imageEdit: { sourceRelativePath: "media/generated/source.jpg", edits: [
- { prompt: expect.stringContaining("A red balloon"), x: 25, y: 19, width: 51, height: 39 },
- { prompt: expect.stringContaining("A blue boat"), x: 25, y: 19, width: 51, height: 39 },
+ expect(request).toMatchObject({ stillImage: true, frames: 1, canvasWidth: 96, canvasHeight: 64, imageEdit: { sourceRelativePath: "media/generated/source.jpg", edits: [
+ { prompt: expect.stringContaining("A red balloon"), x: 24, y: 16, width: 48, height: 32 },
+ { prompt: expect.stringContaining("A blue boat"), x: 24, y: 16, width: 48, height: 32 },
] } });
await finish(queue, request.jobId);
expect(invoke).toHaveBeenCalledWith("save_generated_image", { folderPath: record.folderPath, jobId: request.jobId, format: "png" });
@@ -513,10 +513,26 @@ describe("image generation work", () => {
expect(result.assets[0]).toMatchObject({ id: draftId, imageDraft: false, relativePath: "media/generated/edited.png" });
expect(result.imageScene!.outputAssetId).toBe(draftId);
expect(result.imageScene).toMatchObject({ rootType: "image", sourceImage: { relativePath: "media/generated/edited.png", width: 101, height: 77 } });
- expect(result.assets[0]).toMatchObject({ mimeType: "image/png", imageGeneration: { scene, prompt: expect.stringContaining("Edit 2 (25, 19, 51, 39)") } });
+ expect(result.assets[0]).toMatchObject({ mimeType: "image/png", imageGeneration: { scene, prompt: expect.stringContaining("Edit 2 (24, 16, 48, 32)") } });
expect(restoreGeneratedImage(result, draftId).imageScene!.nodes).toHaveLength(1);
expect(releaseRendered).toHaveBeenCalledWith(request.jobId);
});
+ it("submits the selected image edit resolution, steps and seed to planning and generation", async () => {
+ const { queue } = setup();
+ const record = imageProject();
+ record.config.imageScene = createImageEditScene({ name: "Source", relativePath: "media/source.png", width: 1001, height: 809 });
+ Object.assign(record.config.imageScene, { steps: 32, seed: 123456, outputSize: { width: 672, height: 544 } });
+ record.config.imageScene.nodes[0].description = "Warm up the lighting";
+ const session = queue.project(record);
+ queue.enqueueImage(session, template);
+ await waitFor(() => expect(enqueueSlopfabGeneration).toHaveBeenCalledOnce());
+ const expected = { steps: 32, seed: 123456, canvasWidth: 672, canvasHeight: 544,
+ imageEdit: { sourceRelativePath: "media/source.png", edits: [expect.objectContaining({ x: 0, y: 0, width: 672, height: 544 })] } };
+ expect(vi.mocked(resolveSlopfabPlan).mock.calls[0][0]).toMatchObject(expected);
+ const request = vi.mocked(enqueueSlopfabGeneration).mock.calls[0][0];
+ expect(request).toMatchObject(expected);
+ await queue.cancel(request.jobId);
+ });
it.each(["browse", "modify", "cancel"])("keeps editing versions available during generation: %s", async (action) => {
const { queue } = setup();
const record = imageProject();
diff --git a/src/lib/workQueue.ts b/src/lib/workQueue.ts
index ead35df..b1ab3e4 100644
--- a/src/lib/workQueue.ts
+++ b/src/lib/workQueue.ts
@@ -2,7 +2,7 @@ import { imageSettings } from "./imageSettings";
import { listen } from "@tauri-apps/api/event";
import { invoke } from "@tauri-apps/api/core";
import { createImageEditScene, createImageScene, imageScenePrompt } from "./imageScene";
-import { compileImageEdits, imageEditDebugPrompt } from "./imageEditing";
+import { compileImageEdits, imageEditDebugPrompt, imageEditOutputSize } from "./imageEditing";
import { compileImagePrompt } from "./imagePrompt";
import { compileExtendImage, type ExtendOptions } from "./extendImage";
import { CHARACTER_SHEET_ORDER, CHARACTER_SHEET_VIEWS, characterSheetDimensions, characterSheetViewIndices, characterSheetViews, compileCharacterSheet, type CharacterSheetOptions } from "./characterSheet";
@@ -282,7 +282,7 @@ export class WorkQueue {
...(edit ? [projectItemPath(session.record.folderPath, edit.source)!] : []),
...selected.flatMap((reference) => referenceImages(reference).map((image) => projectItemPath(session.record.folderPath, image)!)),
];
- const { width, height } = edit?.source ?? outputDimensions(imageSettings(current).resolution, imageSettings(current).aspectRatio);
+ const { width, height } = edit ? imageEditOutputSize(scene) : outputDimensions(imageSettings(current).resolution, imageSettings(current).aspectRatio);
const id = `image-${crypto.randomUUID()}`;
const imageDraftId = current.assets.find((asset) => asset.id === scene.outputAssetId && asset.imageDraft)?.id;
// Generating again from a finished image makes a new image in its family.