npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@resizebox/background-remover

v1.0.1

Published

Browser-first AI background removal for JavaScript and TypeScript, built by ResizeBox.com.

Downloads

266

Readme

@resizebox/background-remover

Browser-first AI background removal for JavaScript and TypeScript.

Built by ResizeBox.com, a privacy-focused image toolkit that processes images locally on the user's device.

Install

npm install @resizebox/background-remover

Quick start

import { removeBackground } from '@resizebox/background-remover';

const input = fileInput.files?.[0];
if (!input) throw new Error('Select an image first');

const result = await removeBackground(input, {
  onProgress(progress) {
    if (progress.phase === 'downloading-model') {
      console.log(`Downloading AI model: ${progress.progress}%`);
    }
  },
});

const url = URL.createObjectURL(result.blob);

The first run downloads the AI model from Hugging Face and can take longer. The browser cache is used for later runs.

Background colors

Transparent PNG is the default output. You can also composite the cutout onto a solid six-digit hex color:

const whiteBackground = await removeBackground(file, {
  background: '#ffffff',
});

Preload the model

Use preloadBackgroundRemovalModel() when you want to download and initialize the model before the user's first image is processed.

import { preloadBackgroundRemovalModel } from '@resizebox/background-remover';

await preloadBackgroundRemovalModel({
  onProgress(progress) {
    console.log(progress.phase, progress.progress);
  },
});

Backend selection

The default device is auto. When WebGPU is available, the package tries WebGPU first and falls back to WebAssembly if model loading or inference fails.

await removeBackground(file, { device: 'webgpu' });
await removeBackground(file, { device: 'wasm' });

Supported device values:

  • auto
  • webgpu
  • wasm

Progress states

The onProgress callback can receive:

  • loading-model
  • downloading-model
  • initializing
  • fallback
  • ready
  • processing

downloading-model includes a progress percentage when the model host provides it.

API

removeBackground(input, options?)

Accepts a JPEG, PNG, or WebP Blob or File and returns a PNG Blob plus output metadata.

type RemoveBackgroundOptions = {
  device?: 'auto' | 'webgpu' | 'wasm';
  background?: 'transparent' | string;
  onProgress?: (progress: BackgroundRemovalProgress) => void;
};

The package validates MIME type, file signature, file size, image decoding, and decoded pixel count before model processing. Current limits are exported through backgroundRemoverConfig.

preloadBackgroundRemovalModel(options?)

Downloads and initializes the model without processing an image. Returns the selected backend.

resetBackgroundRemovalModel()

Clears the in-memory model instance so a later call can load it again. Browser-cached model data is not deleted.

BackgroundRemoverError

Validation, model loading, processing, canvas, and encoding failures throw BackgroundRemoverError. Use its code property for application-specific messages.

import {
  BackgroundRemoverError,
  removeBackground,
} from '@resizebox/background-remover';

try {
  await removeBackground(file);
} catch (error) {
  if (error instanceof BackgroundRemoverError) {
    console.error(error.code);
  }
}

Browser requirements

The package is intended for modern browsers and uses browser APIs such as:

  • Blob
  • createImageBitmap
  • Canvas 2D or OffscreenCanvas
  • WebAssembly
  • WebGPU when available

The AI model is not bundled into this npm package. Model data is downloaded from onnx-community/ormbg-ONNX on Hugging Face on first use.

Privacy

Selected images are processed locally on the user's device. Image content is not uploaded to ResizeBox or Hugging Face. Hugging Face is used only to download AI model data.

For the interactive tool, visit ResizeBox.com.

License

MIT