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
Phones: Flip a photo just taken before it is uploaded; sheets lower
Gabriele Lozupone047ea2bce998
diff --git a/src/components/Composer.tsx b/src/components/Composer.tsxindex c7e74f9..412222d 100644--- a/src/components/Composer.tsx+++ b/src/components/Composer.tsx@@ -10,6 +10,7 @@ import {} from "../lib/store";import type { InpaintAction, Plan, Quality } from "../lib/types";import { AdvancedPanel } from "./Advanced";+import { reviewPhotos } from "./PhotoReview";import { AspectGrid, pickAspect, RatioIcon, resolutionLabel, ResolutionMenu } from "./SizeMenus";import { Option, Popover, Seg } from "./ui";@@ -36,7 +37,7 @@ export let promptClosedAt = 0;/** Images from this device (browser picker, drop, paste): uploaded to the service. */export async function uploadFiles(files: File[]) {const recs = [];- for (const f of files) {+ for (const f of await reviewPhotos(files)) {try {recs.push(await api.upload(f, f.name || "pasted.png"));} catch (e) {diff --git a/src/components/PhoneApp.tsx b/src/components/PhoneApp.tsxindex 172f378..929465e 100644--- a/src/components/PhoneApp.tsx+++ b/src/components/PhoneApp.tsx@@ -2,6 +2,7 @@// with its image, versions and prompt. Laid out for an iPhone (safe areas, large round corners,// sheets from the bottom); App.tsx shows it on screens up to 720 px wide (platform.ts isNarrow).+import { PhotoReview } from "./PhotoReview";import { Check, ChevronLeft, EyeOff, Plus, Settings, SquarePen, Trash2, X } from "lucide-react";import { useEffect, useRef, useState, type ReactNode } from "react";import { createPortal } from "react-dom";@@ -65,6 +66,7 @@ export function PhoneApp() {{library ? <Library /> : <ProjectScreen />}{overlay === "inpaint" && <InpaintEditor />}{overlay === "expand" && <ExpandEditor />}+ <PhotoReview /></div>);}diff --git a/src/components/PhotoReview.tsx b/src/components/PhotoReview.tsxnew file mode 100644index 0000000..8455525--- /dev/null+++ b/src/components/PhotoReview.tsx@@ -0,0 +1,118 @@+// A photo just taken with a phone's camera, shown before it is uploaded, with a Flip button:+// Safari's camera gives selfies as the sensor sees them, while the Camera app saves them+// mirrored (Settings → Camera → Mirror Front Camera), so a selfie can look flipped.++import { FlipVertical2, X } from "lucide-react";+import { useEffect, useState, useSyncExternalStore } from "react";+import { createPortal } from "react-dom";+import { haptic } from "../lib/haptics";+import { isNarrow } from "../lib/platform";++interface Pending {+ file: File;+ url: string;+ done: (file: File | null) => void;+}++let pending: Pending | null = null;+const listeners = new Set<() => void>();+const subscribe = (f: () => void) => (listeners.add(f), () => listeners.delete(f));+const settle = (file: File | null) => {+ const p = pending;+ if (!p) return;+ pending = null;+ URL.revokeObjectURL(p.url);+ listeners.forEach((f) => f());+ p.done(file);+};++/** Safari names a picture taken with "Take Photo" image.jpg; ones from the photo library keep+ * their own names. */+export const takenWithCamera = (f: File) => f.name === "image.jpg";++/** On a phone, a photo just taken waits for "Use photo" (flipped or not); the others pass as+ * they are. A cancelled photo is left out. */+export async function reviewPhotos(files: File[]): Promise<File[]> {+ if (!isNarrow()) return files;+ const out: File[] = [];+ for (const f of files) {+ if (!takenWithCamera(f)) {+ out.push(f);+ continue;+ }+ const kept = await new Promise<File | null>((done) => {+ pending = { file: f, url: URL.createObjectURL(f), done };+ listeners.forEach((l) => l());+ });+ if (kept) out.push(kept);+ }+ return out;+}++/** `file` mirrored left to right, as a JPEG. The orientation in its EXIF is applied first+ * (createImageBitmap's default), so the result is what the screen showed. */+async function mirrored(file: File): Promise<File> {+ const bmp = await createImageBitmap(file);+ const cv = document.createElement("canvas");+ cv.width = bmp.width;+ cv.height = bmp.height;+ const ctx = cv.getContext("2d")!;+ ctx.translate(bmp.width, 0);+ ctx.scale(-1, 1);+ ctx.drawImage(bmp, 0, 0);+ bmp.close();+ const blob = await new Promise<Blob | null>((ok) => cv.toBlob(ok, "image/jpeg", 0.92));+ cv.width = cv.height = 0;+ if (!blob) throw new Error("Could not flip the photo.");+ return new File([blob], file.name, { type: "image/jpeg" });+}++/** The review screen, mounted once by the phone layout. */+export function PhotoReview() {+ const p = useSyncExternalStore(subscribe, () => pending);+ const [flip, setFlip] = useState(false);+ const [busy, setBusy] = useState(false);+ useEffect(() => {+ setFlip(false);+ setBusy(false);+ }, [p]);+ if (!p) return null;+ const use = async () => {+ setBusy(true);+ try {+ settle(flip ? await mirrored(p.file) : p.file);+ } catch {+ settle(p.file);+ }+ };+ return createPortal(+ <div className="photo-review" role="dialog" aria-label="Use this photo">+ <div className="hold-save-head">+ <span>Use this photo?</span>+ <button className="glass-btn" title="Cancel" aria-label="Cancel" onClick={() => settle(null)}>+ <X size={20} />+ </button>+ </div>+ <div className="photo-review-img">+ <img src={p.url} alt="Photo just taken" draggable={false} style={flip ? { transform: "scaleX(-1)" } : undefined} />+ </div>+ <div className="photo-review-bar">+ <button+ className={`btn big ${flip ? "on" : ""}`}+ aria-pressed={flip}+ onClick={() => {+ haptic();+ setFlip((f) => !f);+ }}+ >+ {/* lucide's FlipVertical2 is the left-right mirror (its FlipHorizontal2 draws a horizontal axis) */}+ <FlipVertical2 size={18} /> Flip+ </button>+ <button className="btn big primary" disabled={busy} onClick={use}>+ Use photo+ </button>+ </div>+ </div>,+ document.body,+ );+}diff --git a/src/phone.css b/src/phone.cssindex 66fe557..e6fb9c6 100644--- a/src/phone.css+++ b/src/phone.css@@ -327,10 +327,24 @@ html.keyboard .composer-wrap.phone { padding-bottom: 8px; }.hold-save-img > img:not(.develop-ph img) { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 18px; -webkit-touch-callout: default; -webkit-user-select: auto; user-select: auto; }.hold-save-img .develop-ph { inset: 8px 12px calc(env(safe-area-inset-bottom) + 16px); border-radius: 18px; background: #111; }.hold-save-img .develop-ph img { object-fit: contain; }+/* a photo just taken, before it is uploaded (PhotoReview.tsx) */+.photo-review { position: fixed; inset: 0; z-index: 210; display: flex; flex-direction: column; background: #000; color: #fff; animation: fade 0.25s ease-out both; }+.photo-review-img { flex: 1; min-height: 0; display: grid; place-items: center; padding: 8px 12px; }+.photo-review-img img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 18px; transition: transform 0.35s var(--ease); }+.photo-review-bar { flex: none; display: flex; gap: 10px; padding: 8px 16px calc(env(safe-area-inset-bottom) + 12px); }+.photo-review-bar .btn { flex: 1; height: 50px; border-radius: 25px; justify-content: center; font-size: 16px; color: #fff; background: rgba(255, 255, 255, 0.14); border: none; box-shadow: none; }+.photo-review-bar .btn.on { background: rgba(255, 255, 255, 0.34); }+.photo-review-bar .btn.primary { color: #000; background: #fff; }/* ---------- sheets (menus) like iOS: a grabber, large corners, rising from the bottom ---------- */@media (max-width: 720px) {- .popover.sheet { border-radius: 32px; padding: 22px 10px 10px; animation: sheet-up 0.42s var(--ease) both; }+ /* 8 px off the bottom edge like the system's sheets; the home indicator's room is inside */+ .popover.sheet { bottom: 8px; border-radius: 32px; padding: 22px 10px max(10px, calc(env(safe-area-inset-bottom) - 14px)); animation: sheet-up 0.42s var(--ease) both; }+ /* the home-screen app reaches the rounded screen corners: bottom corners concentric with them,+ as the composer card */+ @media (display-mode: standalone) {+ .popover.sheet { border-bottom-left-radius: clamp(32px, calc(env(safe-area-inset-bottom) * 1.3), 46px); border-bottom-right-radius: clamp(32px, calc(env(safe-area-inset-bottom) * 1.3), 46px); }+ }.popover.sheet::before { content: ""; position: absolute; top: 8px; left: 50%; width: 36px; height: 5px; margin-left: -18px; border-radius: 3px; background: var(--surface-3); }.popover.sheet.panel { padding: 24px 16px 16px; }.popover.sheet .opt { width: 100%; min-height: 50px; padding: 0 14px; gap: 14px; border-radius: 18px; font-size: 16px; }