Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
@imgly/background-removal-node
Advanced tools
Remove backgrounds from images in NodeJs environment with ease and no additional costs or privacy concerns. Explore an interactive demo.
November 6th, 2023
: Added support foreground
, background
and mask
export typeNovember 6th, 2023
: Added support for webp
and jpeg
export formats.September 12th, 2023
: We released the code of Background Removal NodeJS.@imgly/background-removal-node
is a powerful npm package that allows developers to seamlessly remove the background from images in NodeJs. With its unique features and capabilities, this package offers an innovative and cost-effective solution for background removal tasks without compromising data privacy.
The key features of @imgly/background-removal-node
are:
@imgly/background-removal-node
provides seamless integration with IMG.LY's CE.SDK, allowing developers to easily incorporate powerful NodeJS image matting and background removal capabilities into their projects.The Neural Network (ONNX model) are hosted on UNPKG, making it readily available for download to all users of the library. See the section Custom Asset Serving if you want to host data on your own servers.
You can install @imgly/background-removal-node
via npm or yarn. Use the following commands to install the package:
npm install @imgly/background-removal-node
import {removeBackground} from "@imgly/background-removal-node";
// const {removeBackground} = require("@imgly/background-removal-node");
let image_src: ImageData | ArrayBuffer | Uint8Array | Blob | URL | string = ...;
removeBackground(image_src).then((blob: Blob) => {
// The result is a blob encoded as PNG. It can be converted to an URL to be used as HTMLImage.src
})
Note: On the first run the wasm and onnx model files are fetched. This might, depending on the bandwidth, take time. Therefore, the first run takes proportionally longer than each consecutive run. Also, all files are cached by the browser and an additional model cache.
The library does not need any configuration to get started. However, there are optional parameters that influence the behaviour and give more control over the library.
type Config = {
publicPath: string; // The public path used for model a
debug: bool; // enable or disable useful console.log outputs
model: 'small' | 'medium'; // The model to use. (Default "medium")
output: {
format: 'image/png' | 'image/jpeg' | 'image/webp'; // The output format. (Default "image/png")
quality: number; // The quality. (Default: 0.8)
type: 'foreground' | 'background' | 'mask'; // The output type. (Default "foreground")
};
};
The onnx model is shipped in various sizes and needs.
On the first run, the necessary data will be fetched and stored in the browser cache. Since the download might take some time, you have the option to tap into the download progress.
let config: Config = {
progress: (key, current, total) => {
console.log(`Downloading ${key}: ${current} of ${total}`);
}
};
Currently, the wasm and onnx neural networks are served via unpkg. For production use, we advise you to host them yourself. Therefore, copy all .wasm and .onnx files to your public path $PUBLIC_PATH
and reconfigure the library.
cp node_modules/@imgly/background-removal-node/dist/*.* $PUBLIC_PATH
import { removeBackground, Config} from "@imgly/background-removal-node"
const public_path = "file://${ASSET_PATH}" ; // the path on the local file system
//const public_path = "https://example.com/assets/" ; // the path assets are served from
let config: Config = {
publicPath: public_path, // path to the wasm files
};
let image_src: Buffer | ArrayBuffer | Uint8Array | Blob | URL | string = ...;
removeBackground(image_src, config).then((blob: Blob) => {
// result is a blob encoded as PNG.
// It can be converted to an URL to be used as HTMLImage.src
const url = URL.createObjectURL(blob);
})
Enable debug outputs and logging to the console
let config: Config = {
debug: true
};
If you are running into CORS issues you might want to pass additional parameters to the fetch function via
let config: Config = {
fetchArgs: {
mode: 'no-cors'
}
};
fetchArgs
are passed as second parameters to the fetch function as described in MDN.
@imgly/background-removal-node
is ideal for developers and projects that require efficient and cost-effective background removal directly in the browser. It caters to a wide range of use cases, including but not limited to:
E-commerce applications that need to remove backgrounds from product images in real time.
Image editing applications that require background removal capabilities for enhancing user experience.
Web-based graphic design tools that aim to simplify the creative process with in-browser background removal.
Whether you are a professional developer or a hobbyist, @imgly/background-removal-node
empowers you to deliver impressive applications and services with ease.
The software is free for use under the GPL License. Please contact support@img.ly for questions about other licensing options.
This library is made by IMG.LY shipping the world's premier SDKs for building creative applications. Start your trial of the CreativeEditor SDK, PhotoEditor SDK & VideoEditor SDK.
FAQs
Background Removal in NodeJS
The npm package @imgly/background-removal-node receives a total of 993 weekly downloads. As such, @imgly/background-removal-node popularity was classified as not popular.
We found that @imgly/background-removal-node demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.