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

isnet-background-removal

v1.0.2

Published

🎨 **AI-powered background removal** using ISNet and ONNX Runtime for **both Node.js and browsers**.

Readme

isnet-background-removal

🎨 AI-powered background removal using ISNet and ONNX Runtime for both Node.js and browsers.

npm version License: MIT

Features

✨ Works in both Node.js and browsers
🚀 Fast inference using ONNX Runtime
🎯 High-quality results with ISNet model
📦 Simple API, no configuration needed
🔧 Customizable for advanced use cases

Installation

npm install isnet-background-removal

Usage

Node.js

import { removeBackground } from 'isnet-background-removal';
import { writeFile } from 'fs/promises';

// From file path
const result = await removeBackground('./image.jpg');
await writeFile('output.png', result);

// From URL
const result = await removeBackground('https://example.com/image.jpg');

// From Buffer
const imageBuffer = await readFile('./image.jpg');
const result = await removeBackground(imageBuffer);

Browser

<!DOCTYPE html>
<html>
<body>
    <input type="file" id="upload" accept="image/*">
    <img id="result">

    <script type="module">
        import { removeBackground } from 'isnet-background-removal';

        document.getElementById('upload').addEventListener('change', async (e) => {
            const file = e.target.files[0];
            const blob = await removeBackground(file);
            document.getElementById('result').src = URL.createObjectURL(blob);
        });
    </script>
</body>
</html>

API

removeBackground(image, config?)

Removes the background from an image.

Parameters:

  • image: Image source
    • Node.js: string (file path or URL), Buffer, or Uint8Array
    • Browser: string (URL), Blob, File, HTMLImageElement, ImageData, or ImageBitmap
  • config (optional): Configuration object

Returns:

  • Node.js: Promise<Buffer> - PNG image buffer
  • Browser: Promise<Blob> - PNG image blob

Configuration Options

All options are optional:

{
  modelUrl?: string;      // Custom model URL (defaults to bundled ISNet model)
  publicPath?: string;    // Path to ONNX Runtime WASM files (browser only)
  numThreads?: number;    // Number of threads (default: 1)
  debug?: boolean;        // Enable debug logging
  device?: 'cpu' | 'webgl' | 'wasm';  // Execution device (browser only)
}

Example with options:

const result = await removeBackground(image, {
  publicPath: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/',
  numThreads: 1,
  debug: true
});

Examples

Node.js Demo

Run the included Node.js demo:

npm run demo:node [image-path-or-url]

Example:

npm run demo:node https://images.unsplash.com/photo-1574158622682-e40e69881006?w=800

Browser Demo

Open examples/browser-demo.html in your browser to try the interactive demo with drag-and-drop support.

How It Works

  1. Image Loading: Loads the input image from various sources
  2. Preprocessing: Resizes image to 1024×1024 (ISNet input size)
  3. Inference: Runs the ISNet model to generate a segmentation mask
  4. Postprocessing: Applies the mask as an alpha channel to create transparency
  5. Output: Returns a PNG image with transparent background

Troubleshooting

Node.js Issues

Error: Canvas/Sharp installation failed

These packages require native compilation. Make sure you have:

  • Python 3.x
  • C++ build tools (Visual Studio on Windows, Xcode on macOS, build-essential on Linux)

Error: Cannot find module

Make sure you're using ES modules. Add "type": "module" to your package.json or use .mjs file extension.

Browser Issues

CORS errors

When loading images from URLs, ensure the server sends proper CORS headers.

WASM loading errors

If you see WASM loading errors, specify the publicPath option:

await removeBackground(image, {
  publicPath: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/'
});

SharedArrayBuffer errors

If you see SharedArrayBuffer errors, either:

  1. Set numThreads: 1 in the config (recommended)
  2. Configure your server with COOP/COEP headers

Performance Tips

  • First run is slower: Model loading and WASM initialization happen on first use
  • Reuse the session: The model session is cached automatically
  • Optimize image size: Smaller images process faster (they're resized to 1024×1024 anyway)
  • Use appropriate threads: In browsers, use numThreads: 1 to avoid COOP/COEP requirements

Model

This package uses the ISNet (Intermediate Supervision Network) model, which provides high-quality salient object detection for background removal.

License

MIT

Credits