Image GenerationIntermediate12 min read

Build an On-Device AI Image Editor That Never Uploads Your Photos

Build a private image editor whose AI runs 100% in the browser using Transformers.js + WebGPU (RMBG-1.4). Remove backgrounds and adjust photos locally — nothing is ever uploaded.

Build an On-Device AI Image Editor That Never Uploads Your Photos

Overview

Most "AI photo editor" tools work by uploading your image to their servers. For a meme, who cares — but for client work, ID documents, product shots, or anything private, sending the file to someone else's cloud is a real problem. The good news: modern browsers can now run genuine AI models entirely on your own device, so your photos never leave your computer. This tutorial shows you how to build a simple, on-device AI image editor whose headline feature — background removal — runs 100% in the browser.


Build an image editor whose AI runs entirely in your browser — remove backgrounds and adjust photos locally, with nothing uploaded to the cloud.
Build an image editor whose AI runs entirely in your browser — remove backgrounds and adjust photos locally, with nothing uploaded to the cloud.


Difficulty: Medium — some HTML/JavaScript · You'll need: a modern browser (Chrome/Edge for WebGPU) and a text editor · Cost: free, open-source · Updated: September 2026

Why On-Device Matters

A cloud editor's flow is: upload your photo → their server processes it → you download the result. That upload is the whole risk. An on-device editor cuts it out: the model runs on your machine, and the image stays with you. That's not just nice-to-have — for healthcare, legal, or client-confidential images, "the file never leaves my computer" can be a hard requirement.

On-device flow: your photo goes into the browser, the AI model runs locally (WebGPU), and you get the edited result — with nothing sent to the cloud.
On-device flow: your photo goes into the browser, the AI model runs locally (WebGPU), and you get the edited result — with nothing sent to the cloud.

The Real Tech: Transformers.js + WebGPU

Here's what actually makes this possible (and what the old "upload to MobileNet" tutorials got wrong — an image classifier like MobileNet labels a photo, it doesn't edit it). The right tool is Transformers.js, Hugging Face's library that runs real AI models directly in the browser using WebGPU (fast) or WebAssembly (universal fallback). For background removal it uses RMBG-1.4, an open model from BRIA AI.

The official WebGPU background-removal demo: "Runs locally in your browser, powered by the RMBG V1.4 model from BRIA AI."
The official WebGPU background-removal demo: "Runs locally in your browser, powered by the RMBG V1.4 model from BRIA AI."

The fastest way to see it: open the official demo below, drop in a photo, and watch your background vanish — with your network tab showing zero image uploads.

WebGPU Background Removal (live demo)

A working, in-browser background remover powered by Transformers.js and the RMBG-1.4 model. Runs locally — your image never leaves your device.

xenova-remove-background-webgpu.static.hf.space

Who This Is For

  • Freelancers and small businesses handling client or product photos who can't upload to third-party clouds.
  • Privacy-minded creators who want AI editing without the data trade-off.
  • Beginner builders curious how AI can run in a plain web page.
  • Path A: Just Use the Open-Source App (no build)

    If you want the result now, you don't have to write anything. The demo above is open source; you can run the same thing locally. addyosmani/bg-remove is a clean, free, client-side background remover built on Transformers.js — clone it, run it, and everything processes on your machine.

    bg-remove — private, client-side background removal

    An open-source React app that removes image backgrounds entirely in your browser with Transformers.js. Files never leave your device.

    github.com

    Path B: Build Your Own (single HTML file)

    Want to understand it? Here's the core of an on-device background remover in one file. Save it as editor.html and open it in Chrome or Edge.

    Step 1: Load Transformers.js and the model

    html
    <input type="file" id="file" accept="image/*">
    <canvas id="out"></canvas>

    <script type="module">
    import { AutoModel, AutoProcessor, RawImage }
    from "https://cdn.jsdelivr.net/npm/@huggingface/transformers";

    // Downloads once, then cached. Uses WebGPU when available.
    const model = await AutoModel.from_pretrained("briaai/RMBG-1.4");
    const processor = await AutoProcessor.from_pretrained("briaai/RMBG-1.4");
    </script>

    Step 2: Remove the background locally

    javascript
    document.getElementById("file").onchange = async (e) => {
      const url = URL.createObjectURL(e.target.files[0]);
      const image = await RawImage.fromURL(url);          // stays in memory, not uploaded

    const { pixel_values } = await processor(image); // preprocess
    const { output } = await model({ input: pixel_values }); // run the model on-device

    // output is an alpha mask; scale it back to the image size
    const mask = await RawImage.fromTensor(
    output[0].mul(255).to("uint8")
    ).resize(image.width, image.height);

    // draw the photo, then apply the mask as transparency
    const canvas = document.getElementById("out");
    canvas.width = image.width; canvas.height = image.height;
    const ctx = canvas.getContext("2d");
    ctx.drawImage(image.toCanvas(), 0, 0);
    const px = ctx.getImageData(0, 0, image.width, image.height);
    for (let i = 0; i < mask.data.length; i++) px.data[i * 4 + 3] = mask.data[i];
    ctx.putImageData(px, 0, 0);
    };

    That's it — a real background remover, with no server. The processor config for RMBG-1.4 can be fiddly across versions, so if a call complains, copy the exact, maintained setup from the open-source app in Path A.

    Before and after: AI background removal that runs on your device — the subject is cut cleanly onto a transparent background.
    Before and after: AI background removal that runs on your device — the subject is cut cleanly onto a transparent background.

    Step 3: Add basic adjustments (no AI needed)

    Not every edit needs a model. Brightness, contrast, and grayscale are simple canvas math — and also 100% local:

    javascript
    // grayscale example, applied to the same canvas pixels
    for (let i = 0; i < px.data.length; i += 4) {
      const g = 0.299px.data[i] + 0.587px.data[i+1] + 0.114*px.data[i+2];
      px.data[i] = px.data[i+1] = px.data[i+2] = g;
    }
    

    Combine the AI background removal with a few canvas filters and you've got a genuinely useful, private editor.

    Common Mistakes to Avoid


  • Using a classifier instead of a segmentation model. MobileNet/ImageNet models label images; they can't remove a background. Use RMBG-1.4 (or MODNet) for editing.

  • Expecting instant first load. The model downloads once (tens of MB). It's cached afterward, but warn users on the first run.

  • Assuming every browser is fast. WebGPU (Chrome/Edge) is quick; the WASM fallback works everywhere but is slower. Test on a modern browser.

  • Overpromising. Background removal runs great locally; full object-removal/inpainting is heavier and still mostly cloud. Be honest about scope.
  • Pro Tips

  • Verify it's truly local. Open your browser's Network tab while editing — you should see the model download once and no image uploads. That's your privacy proof.
  • Cache the model. Transformers.js caches weights after the first load, so repeat edits are instant.
  • Offer a "try example" image so first-time users see it work before committing their own photo.
  • Export as PNG to preserve the transparent background.
  • Start from the open-source app and customize — faster than wiring everything from scratch.
  • Key Takeaways

  • On-device AI editing is real — Transformers.js runs models like RMBG-1.4 in your browser, so photos are never uploaded.
  • Background removal is the local sweet spot, and it works genuinely well.
  • Two paths: run the open-source app as-is, or build a single-file editor yourself.
  • Not everything needs AI — brightness/contrast/grayscale are simple, local canvas math.
  • Be honest about limits: first-load model download, WebGPU for speed, and heavier edits still favor the cloud.
  • Transformers.js — run AI models in the browser

    Hugging Face's library for on-device AI via WebGPU/WebAssembly. The engine behind private, no-upload image editing in a plain web page.

    huggingface.co

    Sources: Transformers.js · WebGPU Background Removal demo · bg-remove (GitHub)

    Library APIs and model configs change; if a snippet errors, copy the current, maintained setup from the open-source app linked above.

    Learn AI, after work

    Track your progress, earn XP, and unlock more free tutorials in the AfterWork Bytes app.

    Open this tutorial in the app

    More AI tutorials