![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
remove.bg
Advanced tools
Readme
The AWESOME remove.bg API is quite easy to use, but it can always be easier - that's where this package comes in.
Get your API key from the remove.bg website. At the moment it's early access, so it may take some time to get yours.
npm i remove.bg
Look at the various removeFrom*.ts
files in the examples folder, or check out the snippets below.
Curious how to use async/await
? That's another reason to check out those examples.
The common input parameters of all three currently supported removeBackgroundFrom*
functions are:
Property | Mandatory | Type | Description |
---|---|---|---|
apiKey | Y | string | The API key you got from the remove.bg website. |
size | N | "regular" / "hd" | The returned size of the image. The cheaper "regular" option is default. |
outputFile | N | string | The path to save the file returned by the API. |
And the output properties are:
Property | Type | Description |
---|---|---|
base64img | string | Base64 encoded representation of the returned image. |
removeBackgroundFromImageFile
Remove the background from a local file.
import { RemoveBgResult, RemoveBgError, removeBackgroundFromImageFile } from "remove.bg";
const localFile = "./local/file/name.jpg";
const outputFile = `${__dirname}/out/img-removed-from-file.png`;
removeBackgroundFromImageFile({
path: localFile,
apiKey: "YOUR-API-KEY",
size: "regular",
outputFile
}).then((result: RemoveBgResult) => {
console.log(`File saved to ${outputFile}`);
const base64img = result.base64img;
}).catch((errors: Array<RemoveBgError>) => {
console.log(JSON.stringify(errors));
});
removeBackgroundFromImageUrl
Remove the background from a remote file (URL).
import { RemoveBgResult, RemoveBgError, removeBackgroundFromImageUrl } from "remove.bg";
const url = "https://domain.tld/path/file.jpg";
const outputFile = `${__dirname}/out/img-removed-from-file.png`;
removeBackgroundFromImageUrl({
url,
apiKey: "YOUR-API-KEY",
size: "regular",
outputFile
}).then((result: RemoveBgResult) => {
console.log(`File saved to ${outputFile}`);
const base64img = result.base64img;
}).catch((errors: Array<RemoveBgError>) => {
console.log(JSON.stringify(errors));
});
removeBackgroundFromImageBase64
Remove the background from a base64 encoded file.
import { RemoveBgResult, RemoveBgError, removeBackgroundFromImageBase64 } from "remove.bg";
import * as fs from "fs";
const localFile = "./local/file/name.jpg";
const base64img = fs.readFileSync(localFile, { encoding: "base64" });
const outputFile = `${__dirname}/out/img-removed-from-file.png`;
removeBackgroundFromImageBase64({
base64img,
apiKey: "YOUR-API-KEY",
size: "regular",
outputFile
}).then((result: RemoveBgResult) => {
console.log(`File saved to ${outputFile}`);
const base64img = result.base64img;
}).catch((errors: Array<RemoveBgError>) => {
console.log(JSON.stringify(errors));
});
FAQs
A simple but effective wrapper for the remove.bg API
The npm package remove.bg receives a total of 12,493 weekly downloads. As such, remove.bg popularity was classified as popular.
We found that remove.bg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.