Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any npm package for removing background from an image? [closed]

Is there anyone who knows how to remove background from an image with the help of any package?

I tried with remove.bg package, but it seems like a paid service.

like image 267
Dev_spidey Avatar asked Dec 07 '25 06:12

Dev_spidey


2 Answers

Disclaimer, I'm the author of rembg.js.

Yes there is, https://www.rembg.com is the only api that allows free API query.

However this is free up to 60 removals per month, it is still great offer when you compare it to other competitors as they do NOT even allow free background removal through API. if you look at the pricing it is actually extremally cheap subscription starting from 1$ a month per 100 removals. you can also get unlimited access.

npm i --save @remove-background-ai/rembg.js

then create index.mjs:

import  { rembg } from '@remove-background-ai/rembg.js';
import dotenv from 'dotenv';
// Load environment variables from .env file
dotenv.config();

// API_KEY will be loaded from the .env file
const API_KEY = process.env.API_KEY;

// log upload and download progress
const onDownloadProgress = console.log;
const onUploadProgress = console.log;

rembg({
    apiKey: API_KEY,
    inputImage: './input.png',
    onDownloadProgress,
    onUploadProgress
}).then(({ outputImagePath, cleanup }) => {
    console.log('path', outputImagePath);
    // if called, it will cleanup (delete from disk) your removed background image
    // cleanup();
});

If you want to show progress bar for upload/download you can create your own onDownloadProgress and onUploadProgress callbacks. both callback accepts AxiosProgressEvent as an event params, in my test i was able to remove background and here is the output :

enter image description here

like image 163
Marwen Trabelsi Avatar answered Dec 09 '25 19:12

Marwen Trabelsi


You can check rembg. Although it works in python https://github.com/danielgatis/rembg

like image 35
Shreesh babu Avatar answered Dec 09 '25 20:12

Shreesh babu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!