JSPM

  • Created
  • Published
  • Downloads 15651
  • Score
    100M100P100Q148514F

Background Removal in the browser

Package Exports

  • @imgly/background-removal
  • @imgly/background-removal/dist/browser.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@imgly/background-removal) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Background Removal in the Web Browser

Getting Started

npm install @imgly/background-removal

or

yarn add @imgly/background-removal

Usage

import imgly_bg_remove from `@imgly/background-removal`

let image_src: ImageData | ArrayBuffer | Uint8Array | Blob | URL | string = ...;

imgly_bg_remove(image_src).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);
})

Custom Asset Serving

Currently, the wasm and onnx neural networks are served via unpkg. For production use, we advise to host them yourself. Therefore, copy all .wasm and .onnx files to your public path and reconfigure the library

cp node_modules/@imgly/background-removal/dist/*.wasm $PUBLIC_PATH
cp node_modules/@imgly/background-removal/dist/*.onnx $PUBLIC_PATH
import imgly_bg_remove, {Config} from `@imgly/background-removal`

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: ImageData | ArrayBuffer | Uint8Array | Blob | URL | string = ...;

imgly_bg_remove(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);
})