Back to Home
Official NPM Package • v1.0.0

In-Browser AI Background Removal for Your Web Apps

Integrate Pixir's production AI engine into your own JavaScript and TypeScript projects. Powered by Bria AI RMBG-1.4 and WebGPU hardware acceleration. 100% private • Zero server calls • Zero cloud infrastructure costs.

MIT Open-Source WrapperWebGPU & WASM SIMDHair & Fur Guided Filter58 kB Lightweight Tarball
$npm install @pixir/background-remover onnxruntime-web

Three Simple Steps to Get Started

Zero complicated model setups. The package automatically handles caching, WASM runtimes, and WebGPU fallback.

01

Install Package & Runtime

Install @pixir/background-remover alongside the onnxruntime-web peer dependency.

npm i @pixir/background-remover onnxruntime-web
02

Import removeBackground

Pass any File, Blob, URL, or Canvas. The model compiles directly on the client's GPU.

const blob = await removeBackground(file);
03

Display or Download PNG

Receive a crisp 32-bit transparent PNG with hair wisps and edge detail preserved, ready for instant rendering or user download.

img.src = URL.createObjectURL(blob);

Framework Integration Guides

Works seamlessly in Vanilla JS, TypeScript, React 18, Next.js, and Canvas pipelines.

main.ts
import { removeBackground } from "@pixir/background-remover";

const fileInput = document.getElementById("fileInput") as HTMLInputElement;

fileInput.addEventListener("change", async (e) => {
  const file = fileInput.files?.[0];
  if (!file) return;

  // Execute in-browser AI segmentation
  const resultBlob = await removeBackground(file, {
    device: "auto",      // WebGPU first, then WASM
    refineEdges: true,   // Guided filter edge refinement
    progress: (info) => {
      console.log(`[${info.stage}] ${Math.round(info.progress * 100)}%: ${info.message}`);
    }
  });

  // Display cutout image
  const url = URL.createObjectURL(resultBlob);
  const img = document.createElement("img");
  img.src = url;
  document.body.appendChild(img);
});

Full Configuration Options Reference

All parameters available in RemoveBackgroundOptions.

OptionTypeDefaultDescription
device'auto' | 'webgpu' | 'wasm''auto'Execution provider backend. 'auto' prefers WebGPU, falling back to single-threaded WASM SIMD.
refineEdgesbooleantrueRuns Fast Guided Image Filter to preserve fine hair, pet fur, and translucent fabrics.
modelPathstringHugging Face CDNCustom URL or relative path to self-hosted rmbg_quantized.onnx for offline environments.
wasmPathstringjsDelivr CDNCustom path for onnxruntime-web WASM binaries.
refinementOptionsRefinementOptions{}Fine-tuning: radius (default 3), eps (0.001), fgThreshold (0.95), bgThreshold (0.03), defringe (true).
outputType'image/png' | 'image/webp''image/png'Desired output MIME format when returning a Blob.
qualitynumber0.95Compression quality for lossy formats like webp (0.0 to 1.0).
progress(info: ProgressInfo) => voidundefinedGranular callback reporting stage, percentage (0.0 to 1.0), and message.
signalAbortSignalundefinedAbortController signal to cancel download or inference operations.

Why Developers Choose @pixir/background-remover

A modern client-side architecture without viral licensing hurdles.

Capability@pixir/background-remover@imgly/background-removalCloud APIs (remove.bg)
Software LicenseMIT PermissiveAGPL v3 (Viral Copyleft)Proprietary Closed
Privacy & Data Security100% Client-Side (Zero Server)Client-SideImages Sent to Third Party
Edge & Hair QualityBria RMBG-1.4 + Guided FilterISNet DownsampledHigh
Hardware AccelerationNative WebGPU + WASM SIMDWASM Multi-thread chunksCloud Servers
Per-Image Cost$0.00 (Zero Server Costs)$0.00 (Requires AGPL)$0.20 – $1.00 / image

Frequently Asked Developer Questions

Answers to common architecture, deployment, and integration questions.

No. Unlike libraries that demand SharedArrayBuffer multi-threading, @pixir/background-remover configures single-threaded execution by default (ort.env.wasm.numThreads = 1). This ensures zero CORS or header friction on Vercel, Netlify, Cloudflare Pages, or traditional static hosting.
Yes. Because neural inference relies on browser APIs (Canvas, WebGPU, WebAssembly), simply mark your component with "use client" in Next.js App Router, or load it dynamically using next/dynamic with { ssr: false }.
Yes. Download the ~42.3 MB rmbg_quantized.onnx file into your public folder (e.g. /public/models/rmbg_quantized.onnx) and pass modelPath: "/models/rmbg_quantized.onnx" into removeBackground. You can also self-host the onnxruntime-web WASM binaries using wasmPath.
The package utilizes the browser CacheStorage API (caches.open("pixir-model-cache")). On the first execution, the model is downloaded and cached locally on the user device. Subsequent visits or page refreshes load the model instantly with zero network download.
The package source code (wrapper, tensor math, sub-pixel bilinear interpolation, and guided filter matting) is licensed under the permissive MIT License. The RMBG-1.4 model weights are created by BRIA AI and distributed under CC BY-NC 4.0. Non-commercial and research use is 100% free; commercial deployments require obtaining a license from BRIA AI.

Try the Pixir Web Studio Live

Experience the native AI engine in our production studio with full 4K export and canvas tools.

Open Free Studio