KotoFon is a React PWA for replacing backgrounds in cat photos. It keeps the original cat pixels, builds a foreground mask in the browser, generates or creates a clean background plate, and composites the final image locally.
The app is designed for pet adoption portraits, shelter posts, and quick social media images where the cat should stay real and only the surrounding scene should change.
- Upload JPEG, PNG, WebP, and HEIC photos.
- Use camera capture on supported devices.
- Crop photos to common aspect ratios or keep the original frame.
- Create an AI foreground mask in the browser with manual brush and eraser fixes.
- Choose background presets such as sofa, studio, windowsill, armchair, blanket, greenery, or random.
- Generate AI background plates through OpenRouter with primary and fallback models.
- Use the local studio background without an external generation request.
- Composite the final image locally, compare before and after, share, download, and save history in the browser.
- Add an optional sticker before export.
- React 18
- TypeScript
- Vite
- Tailwind CSS
- vite-plugin-pwa
- OpenRouter image generation through a small Node.js proxy
- Browser segmentation with
@imgly/background-removalandonnxruntime-web - Local browser history with
idb-keyval
- Node.js 18 or newer.
- An OpenRouter API key for AI generated backgrounds.
The original photo is processed in the browser for crop, mask, and composition. OpenRouter receives only the generated background prompt and placement metadata, not the source photo.
npm installnpm run devThis starts the Vite development server for UI work. Full background generation requires the Node.js proxy from
server.mjs or an equivalent reverse proxy for /api/openrouter/*.
npm run build
OPENROUTER_API_KEY=sk-or-v1-your-token PORT=5174 node server.mjsThen open:
http://127.0.0.1:5174
OPENROUTER_API_KEY provides a shared server-side key. Users can also enter their own OpenRouter key in the app
settings; the browser sends it to the local proxy through X-OpenRouter-Key.
npm run buildThe production build is written to dist/.
Runtime settings are stored in public/app-config.json:
openRouter.primaryBackgroundModelsets the default image model.openRouter.fallbackBackgroundModelandopenRouter.secondaryFallbackBackgroundModelset fallback models.openRouter.imageSizecontrols generated image size for models that support it.openRouter.timeoutMscontrols request timeout.camera.enabledtoggles camera capture.imageProcessing.maxSourceSidePxandimageProcessing.jpegQualitycontrol local image preparation.
Deployment examples are available in deploy/:
kotofon.env.examplekotofon.servicenginx-kotofon.conf
npm run dev # Start Vite for frontend development
npm run build # Type-check and build production assets
npm run preview # Preview the Vite production build
npm run generate-icons # Generate app iconsUse node server.mjs for the production proxy flow because npm run preview does not provide the OpenRouter API proxy.
public/ Runtime config and app icons
src/ React app, image processing, masks, storage, and UI components
deploy/ Example systemd, env, and nginx files
scripts/ Utility scripts
server.mjs Static file server and OpenRouter proxy
MIT