UNPKG

@remove-background-ai/rembg.js

Version:

A simple wrapper for the https://www.rembg.com API

47 lines (46 loc) 2.16 kB
/// <reference types="node" /> import { AxiosProgressEvent } from 'axios'; type InputType = string | Buffer | { base64: string; }; type Options = { returnMask?: boolean; returnBase64?: boolean; w: number; h: number; exact_resize?: boolean; }; /** * Removes the background from an image using the rembg.com API. * * @param apiKey - The API key for rembg.com. * @param inputImage - file path, Buffer, or an object with a { base64: string } property. * @param onUploadProgress - A callback function to handle upload progress events. Defaults to console.log. * @param onDownloadProgress - A callback function to handle download progress events. Defaults to console.log. * @param Options - set of options for image Post processing. * @param options.returnMask - If true, returns the alpha-Matte (mask) image instead of the image. * @param options.returnBase64 - If true, returns the output image as a Base64 string instead of saving it to a file. * @param options.w - The width of the output image. * @param options.h - The height of the output image. * @param options.exact_resize - If true, the output image will be resized to the specified width and height. * @returns If returnBase64 is true, returns an object with the base64Image property containing the Base64 string of the output image. * If returnBase64 is false, returns an object with the outputImagePath property containing the path to the output image file, * and the cleanup function to delete the temporary file. * @throws Throws an error if the API key is not provided or if the request fails. */ export declare const rembg: ({ apiKey, inputImage, options, onUploadProgress, onDownloadProgress, }: { apiKey: string; inputImage: InputType; options?: Options | undefined; onUploadProgress: (progressEvent: AxiosProgressEvent) => void; onDownloadProgress: (progressEvent: AxiosProgressEvent) => void; }) => Promise<{ base64Image: string; outputImagePath?: undefined; cleanup?: undefined; } | { outputImagePath: string; cleanup: () => Promise<void>; base64Image?: undefined; }>; export default rembg;