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

js-image-bg-remover

v1.1.3

Published

Fast, portable background removal using WASM and U-2-Net

Readme

js-image-bg-remover

High-performance, portable background remover using U-2-Net and onnxruntime-web (WASM). Works in Node.js, serverless, Docker, and browser environments. No native dependencies—just npm install and go!

Features

  • 🚀 Fast: WASM inference, much faster than pure JS
  • 🖼️ Accurate: Uses U-2-Net for high-quality matting
  • 📦 Portable: No native deps, works everywhere Node.js runs
  • 🛠️ CLI & API: Use as a CLI or programmatically
  • 📊 Benchmarks: Compare with other JS-based removers
  • 🧑‍💻 Open source: Easy to contribute and extend

Requirements

  • Node.js >= 18.0.0 (for ESM and modern features)
  • 2GB+ RAM recommended
  • ~200MB disk space for model
  • Supported platforms: Linux, macOS, Windows

Installation

npm install js-image-bg-remover

Ubuntu/Debian Server Setup

If you're running on Ubuntu/Debian server, you'll need these system dependencies:

# Install required system packages
sudo apt-get update
sudo apt-get install -y build-essential libvips libvips-dev

# Optional: For HEIC/AVIF support
sudo apt-get install -y libheif-dev

# Optional: Set custom model directory for production
export BG_REMOVER_MODEL_DIR=/path/to/models

Usage

JavaScript (ESM)

import { removeBackground } from 'js-image-bg-remover';

// Basic usage
await removeBackground('input.jpg', 'output.png');

// With custom model directory
await removeBackground('input.jpg', 'output.png', {
  modelDir: '/path/to/models'
});

// Process multiple images
const images = ['img1.jpg', 'img2.jpg', 'img3.jpg'];
await Promise.all(
  images.map(img => removeBackground(img, `output_${img}.png`))
);

JavaScript (CommonJS)

const { removeBackground } = require('js-image-bg-remover');

async function processImage() {
  await removeBackground('input.jpg', 'output.png');
}

TypeScript

import { removeBackground, RemoveBackgroundOptions } from 'js-image-bg-remover';

// Basic usage with type checking
await removeBackground('input.jpg', 'output.png');

// With typed options
const options: RemoveBackgroundOptions = {
  modelDir: '/custom/models',
  showProgress: true
};

await removeBackground('input.jpg', 'output.png', options);

// In an async function with error handling
async function processImage(input: string, output: string) {
  try {
    await removeBackground(input, output);
    console.log('Background removed successfully');
  } catch (err) {
    console.error('Failed to remove background:', err);
  }
}

CLI Usage

# Basic usage
cleancut input.jpg -o output.png

# Custom model directory
cleancut input.jpg -o output.png --model-dir /path/to/models

# Process multiple images
cleancut *.jpg --output-dir ./processed

How it Works

This package uses the U-2-Net model for high-quality background removal:

  • Model: U-2-Net - A state-of-the-art deep learning model for salient object detection
  • Processing:
    • Downloads U-2-Net ONNX model (~176MB) on first use
    • Preprocesses images to 320x320 tensors
    • Runs WASM inference with onnxruntime-web
    • Postprocesses matte and composites transparent PNG
  • Performance: WASM-based inference is significantly faster than pure JS implementations

Benchmarks

Benchmarks are included in the benchmarks/ folder. Run:

npm run bench

Sample benchmark results:

Size      | Avg (s) | Min (s) | Max (s)
---------|---------|---------|----------
500x500  |    0.8  |    0.7  |    0.9
1024x1024|    1.2  |    1.0  |    1.4
2048x2048|    2.5  |    2.2  |    2.8

Factors affecting performance:

  • Image size
  • CPU speed
  • Available RAM
  • Disk speed (for model loading)

Production Tips

  1. System Requirements:

    • Node.js >= 14.0.0
    • 2GB+ RAM recommended
    • ~200MB disk space for model
  2. Docker Setup:

FROM node:18
RUN apt-get update && apt-get install -y \
    build-essential libvips libvips-dev \
    && rm -rf /var/lib/apt/lists/*
ENV BG_REMOVER_MODEL_DIR=/app/models
VOLUME /app/models
  1. Model Storage:
# Store model in shared location
export BG_REMOVER_MODEL_DIR=/shared/models

Contributing

We welcome contributions! Here's how you can help:

  1. Code Contributions:

    • Fork the repository
    • Create a feature branch
    • Submit a Pull Request
  2. Bug Reports:

    • Use the GitHub issue tracker
    • Include sample images when relevant
    • Describe expected vs actual behavior
  3. Feature Requests:

    • Open an issue with the "enhancement" label
    • Describe your use case

See CONTRIBUTING.md for detailed guidelines.

License

This project is MIT licensed. See the LICENSE file for details.

Model Attribution

This software uses the U-2-Net model created by Xuebin Qin et al. If you use this software in academic work, please cite:

@InProceedings{Qin_2020_PR,
    title = {U2-Net: Going Deeper with Nested U-Structure for Salient Object Detection},
    author = {Qin, Xuebin and Zhang, Zichen and Huang, Chenyang and Dehghan, Masood and Zaiane, Osmar and Jagersand, Martin},
    journal = {Pattern Recognition},
    volume = {106},
    pages = {107404},
    year = {2020}
}

The U-2-Net model is licensed under the Apache-2.0 license. The model weights are automatically downloaded from the official repository.

Author

Sagar Regmi

Support

If you find this project helpful, please consider:

  • Giving it a star ⭐ on GitHub
  • Contributing to its development
  • Reporting issues or suggesting features
  • Sharing it with others who might find it useful

Links