Edit photos by describing the change, on your own GPU. A free, open-source alternative to Nano Banana and ChatGPT image editing: photos stay on your computer, no daily limit. One installer for Windows, Mac and Linux sets up the best open model (Qwen-Image 2.1). MCP server for AI agents.
TypeScript ai-photo-editorcomfyui-alternativegenerative-fillimage-editingimage-generationinpaintinglinuxlocal-aimacosmcpmcp-servernano-banana-alternativeofflinephoto-editorprivacyqwen-imageqwen-image-2-1stable-diffusion-cppvulkanwindows
UI fixes from GitHub and Reddit reports for the next release
Gabriele Lozupone076efab1b2d2
diff --git a/src/components/ExpandEditor.tsx b/src/components/ExpandEditor.tsxindex d74edec..8b42583 100644--- a/src/components/ExpandEditor.tsx+++ b/src/components/ExpandEditor.tsx@@ -1,7 +1,7 @@-import { ArrowDown, ArrowLeft, ArrowRight, ArrowUp, Check, ChevronDown, Maximize, RotateCcw, X } from "lucide-react";+import { ArrowDown, ArrowLeft, ArrowRight, ArrowUp, Check, ChevronDown, Lock, LockOpen, Maximize, RotateCcw, X } from "lucide-react";import { useEffect, useLayoutEffect, useRef, useState } from "react";import { urls } from "../lib/api";-import { aspectLabel, expandToRatio, expandToSize, expansionPixels, expansionPreset, parseRatio } from "../lib/logic";+import { LONG_SIDE_PRESETS, aspectLabel, expandToRatio, expandToSize, expansionPixels, expansionPreset, parseRatio, sizeForLongSide } from "../lib/logic";import { focusPrompt, setState, updateComposer, useStore } from "../lib/store";import type { OutpaintSpec, Units } from "../lib/types";import { AspectGrid, RatioIcon } from "./SizeMenus";@@ -10,17 +10,65 @@ import { IconButton, Popover, Seg } from "./ui";type Side = "left" | "right" | "top" | "bottom";const MAX_FINAL = 16384;-/** Exact final size: each side can only grow (an expansion never crops). */+const LOCK_KEY = "kokon.expandRatioLock";+const loadLock = () => {+ try {+ return localStorage.getItem(LOCK_KEY) === "1";+ } catch {+ return false;+ }+};++/** Exact final size: each side can only grow (an expansion never crops). With the lock on,+ * typing one side sets the other to the ratio the fields had when it was locked (#42). */function SizeForm(props: { w: number; h: number; minW: number; minH: number; onApply: (w: number, h: number) => void }) {const [w, setW] = useState(props.w);const [h, setH] = useState(props.h);+ const [lock, setLock] = useState(loadLock);+ const [ratio, setRatio] = useState(props.w / props.h);const ok = w >= props.minW && h >= props.minH && w <= MAX_FINAL && h <= MAX_FINAL && (w > props.minW || h > props.minH);+ const toggleLock = () => {+ const on = !lock;+ setLock(on);+ if (on && w > 0 && h > 0) setRatio(w / h);+ try {+ localStorage.setItem(LOCK_KEY, on ? "1" : "0");+ } catch {+ // the lock just isn't remembered+ }+ };+ const typeW = (v: number) => {+ setW(v);+ if (lock && v > 0) setH(Math.round(v / ratio));+ };+ const typeH = (v: number) => {+ setH(v);+ if (lock && v > 0) setW(Math.round(v * ratio));+ };+ // Screen presets keep the fields' ratio; one smaller than the image can't be reached.+ const presets = LONG_SIDE_PRESETS.map((p) => ({ ...p, size: sizeForLongSide(w > 0 && h > 0 ? w / h : ratio, p.long) }));return (<div className="expand-size"><span className="pair">- <input className="input" type="number" min={props.minW} max={MAX_FINAL} value={w} onChange={(e) => setW(Math.round(Number(e.target.value) || 0))} onKeyDown={(e) => e.key === "Enter" && ok && props.onApply(w, h)} aria-label="Final width" />+ <input className="input" type="number" min={props.minW} max={MAX_FINAL} value={w} onChange={(e) => typeW(Math.round(Number(e.target.value) || 0))} onKeyDown={(e) => e.key === "Enter" && ok && props.onApply(w, h)} aria-label="Final width" /><span className="muted">×</span>- <input className="input" type="number" min={props.minH} max={MAX_FINAL} value={h} onChange={(e) => setH(Math.round(Number(e.target.value) || 0))} onKeyDown={(e) => e.key === "Enter" && ok && props.onApply(w, h)} aria-label="Final height" />+ <input className="input" type="number" min={props.minH} max={MAX_FINAL} value={h} onChange={(e) => typeH(Math.round(Number(e.target.value) || 0))} onKeyDown={(e) => e.key === "Enter" && ok && props.onApply(w, h)} aria-label="Final height" />+ <button className={`icon-btn sm ${lock ? "active" : ""}`} onClick={toggleLock} aria-pressed={lock} title={lock ? "Ratio locked: changing one side changes the other" : "Lock the ratio"}>+ {lock ? <Lock size={14} /> : <LockOpen size={14} />}+ </button>+ </span>+ <span className="size-presets">+ {presets.map((p) => (+ <button+ key={p.label}+ className={p.size.width === w && p.size.height === h ? "on" : ""}+ disabled={p.size.width < props.minW || p.size.height < props.minH}+ onClick={() => (setW(p.size.width), setH(p.size.height))}+ title={`${p.size.width}×${p.size.height}`}+ >+ {p.label}+ </button>+ ))}</span>{w > 0 && h > 0 && (<span className="ratio-tag">diff --git a/src/components/SizeMenus.tsx b/src/components/SizeMenus.tsxindex b2475a1..9a19303 100644--- a/src/components/SizeMenus.tsx+++ b/src/components/SizeMenus.tsx@@ -1,6 +1,6 @@import { ArrowLeftRight, Check } from "lucide-react";import { useState } from "react";-import { ASPECTS, aspectLabel, parseRatio, planPipeline, sizeForRatio } from "../lib/logic";+import { ASPECTS, LONG_SIDE_PRESETS, aspectLabel, parseRatio, planPipeline, sizeForLongSide, sizeForRatio } from "../lib/logic";import { getState, updateComposer, useStore } from "../lib/store";import type { Plan, ResolutionMode } from "../lib/types";import { Option } from "./ui";@@ -17,14 +17,14 @@ export function RatioIcon({ ratio, size = 16 }: { ratio: number; size?: number }}/** Two numbers typed by hand (a ratio such as 7:5, or a size such as 1920×1080). */-function PairFields(props: { a: number | ""; b: number | ""; sep: string; max: number; onA: (v: number | "") => void; onB: (v: number | "") => void; label: string; onEnter?: () => void }) {+function PairFields(props: { a: number | ""; b: number | ""; sep: string; max: number; onA: (v: number | "") => void; onB: (v: number | "") => void; label: string; onEnter?: () => void; onFocus?: () => void }) {const num = (v: string): number | "" => (v === "" ? "" : Math.max(0, Math.min(props.max, Number(v) || 0)));const key = (e: React.KeyboardEvent) => e.key === "Enter" && props.onEnter?.();return (<span className="pair" aria-label={props.label}>- <input className="input" type="number" min={1} max={props.max} value={props.a} onChange={(e) => props.onA(num(e.target.value))} onKeyDown={key} />+ <input className="input" type="number" min={1} max={props.max} value={props.a} onChange={(e) => props.onA(num(e.target.value))} onKeyDown={key} onFocus={props.onFocus} /><span className="muted">{props.sep}</span>- <input className="input" type="number" min={1} max={props.max} value={props.b} onChange={(e) => props.onB(num(e.target.value))} onKeyDown={key} />+ <input className="input" type="number" min={1} max={props.max} value={props.b} onChange={(e) => props.onB(num(e.target.value))} onKeyDown={key} onFocus={props.onFocus} /></span>);}@@ -87,18 +87,23 @@ export function ResolutionMenu({ plan, close }: { plan: Plan | null; close: () =setH(nh);if (typeof nw === "number" && typeof nh === "number" && nw >= 64 && nh >= 64) updateComposer({ resolution: "custom", customWidth: nw, customHeight: nh });};+ // The size already in the fields is picked by clicking the row or a field: before, only a+ // changed value picked it, so a size left from an earlier image had to be retyped.+ const pick = () => valid && c.resolution !== "custom" && updateComposer({ resolution: "custom", customWidth: w as number, customHeight: h as number });+ // Screen presets keep the ratio already typed (16:9 when there is none).+ const ratio = valid ? (w as number) / (h as number) : 16 / 9;return (<div className="res-menu">{RES_OPTIONS.filter((o) => o.value !== "source" || editing).map((o) => (<Option key={o.value} selected={c.resolution === o.value} label={o.label} sub={o.sub} onClick={() => (updateComposer({ resolution: o.value }), close())} />))}<div className={`res-custom ${c.resolution === "custom" ? "on" : ""}`}>- <span className="res-custom-head">+ <button className="res-custom-head" onClick={pick}><span className="check">{c.resolution === "custom" && <Check size={15} />}</span>Exact size- </span>+ </button><span className="res-custom-row">- <PairFields a={w} b={h} sep="×" max={4096} onA={(v) => apply(v, h)} onB={(v) => apply(w, v)} label="Width and height" onEnter={close} />+ <PairFields a={w} b={h} sep="×" max={4096} onA={(v) => apply(v, h)} onB={(v) => apply(w, v)} label="Width and height" onEnter={close} onFocus={pick} /><button className="icon-btn sm" title="Swap width and height" onClick={() => apply(h, w)}><ArrowLeftRight size={14} /></button>@@ -109,6 +114,17 @@ export function ResolutionMenu({ plan, close }: { plan: Plan | null; close: () =</span>)}</span>+ <span className="res-custom-row size-presets">+ {LONG_SIDE_PRESETS.map((p) => {+ const s = sizeForLongSide(ratio, p.long);+ const on = c.resolution === "custom" && c.customWidth === s.width && c.customHeight === s.height;+ return (+ <button key={p.label} className={on ? "on" : ""} onClick={() => apply(s.width, s.height)} title={`${s.width}×${s.height}`}>+ {p.label}+ </button>+ );+ })}+ </span></div>{plan && (<div className="res-foot muted">diff --git a/src/components/Stage.tsx b/src/components/Stage.tsxindex fdfa8f8..ee1a4f1 100644--- a/src/components/Stage.tsx+++ b/src/components/Stage.tsx@@ -229,6 +229,14 @@ function Failed({ job, item }: { job: JobView; item: SessionItem }) {);}+function CopyText({ text, title }: { text: string; title: string }) {+ return (+ <IconButton small title={title} onClick={() => void native.copyText(text).then(() => toastInfo("Prompt copied"), toastError)}>+ <Copy size={13} />+ </IconButton>+ );+}+export function InfoPanel({ g }: { g: GenerationRecord }) {const pipeline = pipelineSummary(g);const lut = lutInfo(g);@@ -255,10 +263,16 @@ export function InfoPanel({ g }: { g: GenerationRecord }) {];return (<div className="info-panel" style={{ padding: 8, display: "flex", flexDirection: "column", gap: 6 }}>- <div style={{ fontSize: 13, userSelect: "text", maxHeight: 160, overflow: "auto" }}>{g.prompt}</div>+ <div className="info-prompt">+ <div style={{ fontSize: 13, maxHeight: 160, overflow: "auto" }}>{g.prompt}</div>+ <CopyText text={g.prompt} title={g.original_prompt ? "Copy the prompt Prompt+ wrote" : "Copy the prompt"} />+ </div>{g.original_prompt && (- <div className="muted" style={{ userSelect: "text", maxHeight: 80, overflow: "auto" }}>- <WandSparkles size={11} style={{ verticalAlign: -1 }} /> Written by the prompt enhancer from: “{g.original_prompt}”+ <div className="info-prompt">+ <div className="muted" style={{ maxHeight: 80, overflow: "auto" }}>+ <WandSparkles size={11} style={{ verticalAlign: -1 }} /> Written by the prompt enhancer from: “{g.original_prompt}”+ </div>+ <CopyText text={g.original_prompt} title="Copy your prompt" /></div>)}{g.negative_prompt && <div className="muted">Negative: {g.negative_prompt}</div>}@@ -266,12 +280,12 @@ export function InfoPanel({ g }: { g: GenerationRecord }) {{rows.map(([k, v]) => (<Fragment key={k}><span className="muted">{k}</span>- <span style={{ userSelect: "text", wordBreak: "break-all" }}>{v}</span>+ <span style={{ wordBreak: "break-all" }}>{v}</span></Fragment>))}</div>{g.notes.length > 0 && <div className="muted">{g.notes.join(" ")}</div>}- <div className="muted" style={{ wordBreak: "break-all", userSelect: "text" }}>{g.file_path}</div>+ <div className="muted" style={{ wordBreak: "break-all" }}>{g.file_path}</div></div>);}diff --git a/src/lib/logic.test.ts b/src/lib/logic.test.tsindex 2a1663b..f1e197d 100644--- a/src/lib/logic.test.ts+++ b/src/lib/logic.test.ts@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";import {activeLoras, activeOverrides, buildRequest, composing, editing, reviewRequest, wantsPromptReview, toggleLora, MAX_LORAS, jobPercent, compareBase, composerFromRecord, enhancerApplies, diffPixels, emptyComposer, expansionPixels, expansionPreset, jobLabel, jobSecondsLeft, lutInfo, moveRef, needsPrompt, normalizeQuality, persistentAdvanced, pipelineSummary,planPipeline, remainingSeconds, sizeForWidth, timeAgo, upscaleRequest, upscaleTargets, versionLabels, type JobClock, type Ref,- neighbourAfterRemoval, pageOutdated, previewIndex, starPromptDue, STAR_PROMPT_AFTER, formatBytes, formatDuration, installItemShort, installItemText, installProgress, installStep, installTimeLeft, timelineLinks, undoTarget, aspectLabel, parseRatio, sizeForRatio, expandToRatio, expandToSize, arcLayout,+ neighbourAfterRemoval, pageOutdated, previewIndex, starPromptDue, STAR_PROMPT_AFTER, formatBytes, formatDuration, installItemShort, installItemText, installProgress, installStep, installTimeLeft, timelineLinks, undoTarget, aspectLabel, parseRatio, sizeForRatio, sizeForLongSide, expandToRatio, expandToSize, arcLayout,goneVersions, PREVIEW_SIDE, stageFitsPreview, viewerWantsFull,} from "./logic";import type { GenerationRecord, InstallItem, JobView, LoraItem, Plan } from "./types";@@ -118,6 +118,11 @@ describe("buildRequest", () => {const plain = composerFromRecord({ ...g, original_prompt: null }, { ...emptyComposer(), enhance: true });expect([plain.prompt, plain.enhance]).toEqual(["A tabby cat sleeping on a sunlit windowsill.", false]);});+ it("reusing the settings keeps a fixed seed and leaves a random one random", () => {+ const g = { prompt: "x", original_prompt: null, seed: 77, references: [], mask_input_id: null, outpaint: null, quality: "fast", request: { mode: "auto", seed: 42 } } as unknown as GenerationRecord;+ expect(composerFromRecord(g, emptyComposer()).seed).toBe(42);+ expect(composerFromRecord({ ...g, request: { mode: "auto", seed: null } } as unknown as GenerationRecord, emptyComposer()).seed).toBe(null);+ });it("New image with images makes a new image that uses them as references", () => {const c = { ...emptyComposer(), prompt: "lei che beve questo caffè", refs: [ref(1), ref(2)], create: true, aspect: "4:5" };expect(composing(c) && !editing(c)).toBe(true);@@ -487,6 +492,11 @@ describe("aspect ratios", () => {expect(Math.abs((s.width * s.height) / (1024 * 1024) - 1)).toBeLessThan(0.03);expect(aspectLabel(s.width, s.height)).toBe("16:9");});+ it("sizes a screen preset by its long side, in either orientation", () => {+ expect(sizeForLongSide(16 / 9, 3840)).toEqual({ width: 3840, height: 2160 });+ expect(sizeForLongSide(9 / 16, 1920)).toEqual({ width: 1080, height: 1920 });+ expect(sizeForLongSide(1760 / 2368, 3840)).toEqual({ width: 2854, height: 3840 });+ });it("expands to a ratio or an exact size without cropping", () => {expect(expandToRatio(1000, 1000, 2)).toEqual({ left: 500, right: 500, top: 0, bottom: 0, units: "pixels" });expect(expandToRatio(2000, 1000, 1)).toEqual({ left: 0, right: 0, top: 500, bottom: 500, units: "pixels" });diff --git a/src/lib/logic.ts b/src/lib/logic.tsindex cdab3d4..c0bf8e2 100644--- a/src/lib/logic.ts+++ b/src/lib/logic.ts@@ -235,7 +235,8 @@ export function composerFromRecord(g: GenerationRecord, base: Composer): Composequality: normalizeQuality(g.quality, base.quality),resolution: req?.resolution ?? base.resolution,aspect: req?.aspect_ratio ?? "auto",- seed: null,+ // A seed the user fixed is a setting too; a random one stays random.+ seed: req?.seed ?? null,advanced: cleanAdvanced(req?.advanced ?? {}),// The LoRAs it was made with (none for images made before LoRAs or without them).loras: (g.loras ?? []).map((l) => l.id),@@ -744,6 +745,18 @@ export function sizeForRatio(r: number, area: number, max = 4096): Size {return { width: r16(Math.sqrt(area * r)), height: r16(Math.sqrt(area / r)) };}+/** Common screen sizes by their long side (16:9 gives 1920×1080, 2560×1440, 3840×2160). */+export const LONG_SIDE_PRESETS = [+ { label: "1080p", long: 1920 },+ { label: "1440p", long: 2560 },+ { label: "4K", long: 3840 },+] as const;++/** Width × height with ratio `r` and the given long side; the short side is rounded. */+export function sizeForLongSide(r: number, long: number): Size {+ return r >= 1 ? { width: long, height: Math.max(1, Math.round(long / r)) } : { width: Math.max(1, Math.round(long * r)), height: long };+}+/** Expansion (source pixels, centred) that turns a w×h image into ratio `r` without cropping. */export function expandToRatio(w: number, h: number, r: number): OutpaintSpec {if (w / h < r) {diff --git a/src/lib/native.ts b/src/lib/native.tsindex b2d70ce..4c63e50 100644--- a/src/lib/native.ts+++ b/src/lib/native.ts@@ -4,6 +4,7 @@import { invoke } from "@tauri-apps/api/core";import { getCurrentWindow } from "@tauri-apps/api/window";+import { writeText } from "@tauri-apps/plugin-clipboard-manager";import { ask, open, save } from "@tauri-apps/plugin-dialog";import { inBrowser } from "./platform";@@ -35,6 +36,21 @@ export const native = {const png = await asPng(await res.blob());await navigator.clipboard.write([new ClipboardItem({ "image/png": png })]);},+ /** Text to the clipboard. A browser page on plain http (the LAN) has no clipboard API: the old+ * copy command still works there. */+ copyText: async (text: string) => {+ if (!inBrowser) return writeText(text);+ if (window.isSecureContext && navigator.clipboard?.writeText) return navigator.clipboard.writeText(text);+ const area = document.createElement("textarea");+ area.value = text;+ area.style.position = "fixed";+ area.style.opacity = "0";+ document.body.appendChild(area);+ area.select();+ const ok = document.execCommand("copy");+ area.remove();+ if (!ok) throw new Error("Could not copy the text.");+ },readClipboardImage: async (): Promise<Uint8Array | null> => {if (inBrowser) return null;const buf = await invoke<ArrayBuffer>("read_clipboard_image");diff --git a/src/styles.css b/src/styles.cssindex 77a2fde..b896934 100644--- a/src/styles.css+++ b/src/styles.css@@ -10,6 +10,8 @@--surface: #ededed;--surface-2: #e4e4e4;--surface-3: #d7d7d7;+ /* selected text: clearly apart from every surface it can sit on */+ --selection: #c4c4c4;--border: rgba(0, 0, 0, 0.08);--border-2: rgba(0, 0, 0, 0.14);--text: #0d0d0d;@@ -49,6 +51,7 @@--surface: #1c1c1c;--surface-2: #252525;--surface-3: #313131;+ --selection: #5a5a5a;--border: rgba(255, 255, 255, 0.07);--border-2: rgba(255, 255, 255, 0.14);--text: #f2f2f2;@@ -78,6 +81,7 @@--surface: #262626;--surface-2: #2f2f2f;--surface-3: #3a3a3a;+ --selection: #636363;--checker: #222222;--scrim: rgba(22, 22, 22, 0.85);}@@ -99,7 +103,8 @@ textarea, input[type="text"], input[type="number"] { user-select: text; }button { cursor: pointer; background: none; border: 0; padding: 0; }button:disabled { cursor: default; opacity: 0.4; }:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }-::selection { background: var(--surface-3); }+/* Colour set too: WebKitGTK (Linux) otherwise draws a dark theme's selection near-black (#41). */+::selection, input::selection, textarea::selection { background: var(--selection); color: var(--text); }svg { display: block; flex: none; }.app { display: flex; height: 100%; }@@ -723,7 +728,11 @@ pre.diag { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font/* ---------- aspect ratio and size menus ---------- */.popover.wide { min-width: 0; }/* the width is a class, not inline, so phones can widen it (sheet) */-.info-panel { width: 340px; }+/* Everything in it can be copied. In the stylesheet, not inline: the build adds -webkit-user-select,+ which WebKit (macOS, Linux, iPhone) needs to undo the body's; an inline style gets no prefix. */+.info-panel { width: 340px; user-select: text; }+.info-prompt { display: flex; align-items: flex-start; gap: 4px; }+.info-prompt > div { flex: 1; min-width: 0; }.upscale-menu { width: 300px; }/* Prompt+ menu: one line per choice */.popover.prompt-plus { width: 260px; }@@ -746,9 +755,13 @@ pre.diag { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font.res-menu { width: 340px; }.res-custom { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; border-radius: 9px; }.res-custom.on { background: var(--surface); }-.res-custom-head { display: flex; align-items: center; gap: 10px; font-size: 13px; }+.res-custom-head { display: flex; align-items: center; gap: 10px; font-size: 13px; text-align: left; }.res-custom-head .check { width: 16px; display: grid; place-items: center; }.res-custom-row { display: flex; align-items: center; gap: 6px; padding-left: 26px; }+.size-presets { flex-wrap: wrap; }+.size-presets button { height: 26px; padding: 0 10px; border-radius: 13px; background: var(--surface-2); font-size: 12px; color: var(--text-2); }+.size-presets button:hover:not(:disabled):not(.on) { color: var(--text); }+.size-presets button.on { background: var(--invert-bg); color: var(--invert-text); }.res-foot { padding: 8px 10px 4px; border-top: 1px solid var(--border); margin-top: 4px; font-size: 12px; }.expand-size { width: 280px; display: flex; flex-direction: column; gap: 8px; padding: 6px; font-size: 12px; }.expand-final { color: var(--text); font-weight: 600; }