@jackgreen2018/browser-background-remover
v1.0.1
Published
Browser-based background removal using pre-built WASM. No server uploads, no subscriptions, privacy by design. Free alternative to Remove.bg for Etsy/Shopify sellers.
Readme
@jackgreen2018/browser-background-remover
Browser-based background removal using pre-built WASM. No server uploads, no subscriptions, privacy by design.
Built for Etsy and Shopify sellers who process 10–50 product photos monthly and resent Remove.bg's $7.99/mo subscription.
Install
npm install @jackgreen2018/browser-background-removerUsage
import { removeBackground } from '@jackgreen2018/browser-background-remover';
// From raw bytes
const result = await removeBackground(arrayBuffer, {
threshold: 0.5, // 0.0–1.0, lower = more conservative
blurRadius: 2, // Gaussian blur for soft edges
});
// result.imageData: Uint8Array of PNG bytes with transparent background
// result.alphaMap: Uint8Array of alpha values [0–255] per pixel
// result.width, result.height: output dimensions
// From a File object (browser)
const file = document.querySelector('input[type=file]').files[0];
const result2 = await removeBackgroundFromFile(file, { threshold: 0.4 });API
removeBackground(input, options?)
Remove background from an image.
- input:
ArrayBuffer | Blob— the source image (JPEG or PNG) - options.threshold:
0.0–1.0(default:0.5) — sensitivity for background detection - options.blurRadius:
number(default:2) — Gaussian blur radius for edge softening - returns:
Promise<BackgroundRemovalResult>withimageData,alphaMap,width,height
removeBackgroundFromFile(file, options?)
Convenience wrapper for browser File objects.
Benchmark
Measured on Node.js 22, 5 iterations each, real numbers:
| Image Size | Avg (ms) | Min (ms) | Max (ms) | |---------------|----------|----------|----------| | 100x100px | 4.55 | 2.95 | 10.70 | | 500x500px | 65.39 | 62.88 | 67.75 | | 800x600px | 121.72 | 117.61 | 135.64 | | 1000x1000px | 249.47 | 244.03 | 257.12 |
Comparison: Remove.bg API takes ~2–5 seconds per image (server round-trip + processing). This library runs entirely in-browser at ~5–250ms depending on image size.
How It Works
- WASM decode — Pre-built WebAssembly module decodes JPEG/PNG input
- Background estimation — Samples corner pixels to estimate background color
- Alpha matte — Builds a soft matte via color-distance thresholding
- Edge softening — Applies Gaussian blur to smooth transitions
- PNG encode — Outputs transparent PNG
The WASM binary is pre-built and included in the package. No compilation required.
License
MIT
