Socket
Socket
Sign inDemoInstall

@imgly/background-removal

Package Overview
Dependencies
25
Maintainers
8
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.1 to 1.3.0

dist/014c9e0229363137e92b85ed3c6f56b1386c279cdd9af2d7f1960ed8428b5e94

20

CHANGELOG.md

@@ -7,2 +7,22 @@ # Changelog

## [1.3.0]
### Added
- Resources are now chunked to 4MB for better caching performance and download restart.
- Seperate functions for `removeBackground`, `removeForeground`, and `segmentForeground`. Later will extract the mask only.
- Config option to export 'x-alpha8' format to get receive single channel alpha mask.
### Removed
- Configuration options to specify if background, foreground or mask is exported.
### Changed
- Changed the return value type of the progress callback from undefined to void
- Output is now in the original image size. Mask is upscaled and applied to the original image.
## [1.2.1]

@@ -9,0 +29,0 @@

69

dist/index.d.ts

@@ -10,8 +10,31 @@ declare module '@imgly/background-removal/src/codecs' {

export default removeBackground;
export type { ImageSource, Config };
export { removeBackground, preload };
export { preload, removeBackground, removeForeground, segmentForeground };
export type { Config, ImageSource };
import { Config } from '@imgly/background-removal/src/schema';
type ImageSource = ImageData | ArrayBuffer | Uint8Array | Blob | URL | string;
import { ImageSource } from '@imgly/background-removal/src/utils';
function preload(configuration?: Config): Promise<void>;
/**
* Removes the background from an image.
*
* @param image - The image to remove the background from.
* @param configuration - Optional configuration for the background removal process.
* @returns A Promise that resolves to the resulting image with the background removed.
*/
function removeBackground(image: ImageSource, configuration?: Config): Promise<Blob>;
/**
* Removes the foreground from an image.
*
* @param image - The image to remove the foreground from.
* @param configuration - Optional configuration for the foreground removal process.
* @returns A Promise that resolves to the resulting image with the foreground removed.
*/
function removeForeground(image: ImageSource, configuration?: Config): Promise<Blob>;
/**
* Segments the foreground of an image using a given configuration.
*
* @param image - The image source to segment.
* @param configuration - The optional configuration for the segmentation.
* @returns A Promise that resolves to the segmented foreground as a Blob.
*/
function segmentForeground(image: ImageSource, configuration?: Config): Promise<Blob>;

@@ -29,8 +52,7 @@ }

fetchArgs?: any;
progress?: (args_0: string, args_1: number, args_2: number, ...args_3: unknown[]) => undefined;
progress?: (args_0: string, args_1: number, args_2: number, ...args_3: unknown[]) => void;
model?: "small" | "medium";
output?: {
format?: "image/png" | "image/x-rgba8" | "image/jpeg" | "image/webp";
format?: "image/png" | "image/jpeg" | "image/webp" | "image/x-rgba8" | "image/x-alpha8";
quality?: number;
type?: "background" | "mask" | "foreground";
};

@@ -61,23 +83,20 @@ };

declare module '@imgly/background-removal/src/schema' {
export { ConfigSchema, Config, validateConfig };
export { Config, ConfigSchema, validateConfig };
import { z } from 'zod';
const ConfigSchema: z.ZodDefault<z.ZodObject<{
publicPath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
publicPath: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, string, string>;
debug: z.ZodDefault<z.ZodBoolean>;
proxyToWorker: z.ZodDefault<z.ZodBoolean>;
fetchArgs: z.ZodDefault<z.ZodAny>;
progress: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodString, z.ZodNumber, z.ZodNumber], z.ZodUnknown>, z.ZodUndefined>>;
progress: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodString, z.ZodNumber, z.ZodNumber], z.ZodUnknown>, z.ZodVoid>>;
model: z.ZodDefault<z.ZodEnum<["small", "medium"]>>;
output: z.ZodDefault<z.ZodObject<{
format: z.ZodDefault<z.ZodEnum<["image/png", "image/jpeg", "image/webp", "image/x-rgba8"]>>;
format: z.ZodDefault<z.ZodEnum<["image/png", "image/jpeg", "image/webp", "image/x-rgba8", "image/x-alpha8"]>>;
quality: z.ZodDefault<z.ZodNumber>;
type: z.ZodDefault<z.ZodEnum<["foreground", "background", "mask"]>>;
}, "strip", z.ZodTypeAny, {
format?: "image/png" | "image/x-rgba8" | "image/jpeg" | "image/webp";
format?: "image/png" | "image/jpeg" | "image/webp" | "image/x-rgba8" | "image/x-alpha8";
quality?: number;
type?: "background" | "mask" | "foreground";
}, {
format?: "image/png" | "image/x-rgba8" | "image/jpeg" | "image/webp";
format?: "image/png" | "image/jpeg" | "image/webp" | "image/x-rgba8" | "image/x-alpha8";
quality?: number;
type?: "background" | "mask" | "foreground";
}>>;

@@ -89,8 +108,7 @@ }, "strip", z.ZodTypeAny, {

fetchArgs?: any;
progress?: (args_0: string, args_1: number, args_2: number, ...args_3: unknown[]) => undefined;
progress?: (args_0: string, args_1: number, args_2: number, ...args_3: unknown[]) => void;
model?: "small" | "medium";
output?: {
format?: "image/png" | "image/x-rgba8" | "image/jpeg" | "image/webp";
format?: "image/png" | "image/jpeg" | "image/webp" | "image/x-rgba8" | "image/x-alpha8";
quality?: number;
type?: "background" | "mask" | "foreground";
};

@@ -102,8 +120,7 @@ }, {

fetchArgs?: any;
progress?: (args_0: string, args_1: number, args_2: number, ...args_3: unknown[]) => undefined;
progress?: (args_0: string, args_1: number, args_2: number, ...args_3: unknown[]) => void;
model?: "small" | "medium";
output?: {
format?: "image/png" | "image/x-rgba8" | "image/jpeg" | "image/webp";
format?: "image/png" | "image/jpeg" | "image/webp" | "image/x-rgba8" | "image/x-alpha8";
quality?: number;
type?: "background" | "mask" | "foreground";
};

@@ -122,9 +139,13 @@ }>>;

declare module '@imgly/background-removal/src/utils' {
export { imageDecode, imageEncode, tensorResize, tensorHWCtoBCHW, imageBitmapToImageData, calculateProportionalSize };
export { imageDecode, imageEncode, tensorResizeBilinear, tensorHWCtoBCHW, imageBitmapToImageData, calculateProportionalSize, imageSourceToImageData, ImageSource };
import { NdArray } from 'ndarray';
import { imageDecode, imageEncode } from '@imgly/background-removal/src/codecs';
import { Config } from '@imgly/background-removal/src/schema';
type ImageSource = ImageData | ArrayBuffer | Uint8Array | Blob | URL | string;
function imageBitmapToImageData(imageBitmap: ImageBitmap): ImageData;
function tensorResize(imageTensor: NdArray<Uint8Array>, newWidth: number, newHeight: number): Promise<NdArray<Uint8Array>>;
function tensorHWCtoBCHW(imageTensor: NdArray<Uint32Array>, mean?: number[], std?: number[]): NdArray<Float32Array>;
function tensorResizeBilinear(imageTensor: NdArray<Uint8Array>, newWidth: number, newHeight: number): NdArray<Uint8Array>;
function tensorHWCtoBCHW(imageTensor: NdArray<Uint8Array>, mean?: number[], std?: number[]): NdArray<Float32Array>;
function calculateProportionalSize(originalWidth: number, originalHeight: number, maxWidth: number, maxHeight: number): [number, number];
function imageSourceToImageData(image: ImageSource, config: Config): Promise<NdArray<Uint8Array>>;
export function convertFloat32ToUint8(float32Array: NdArray<Float32Array>): NdArray<Uint8Array>;

@@ -131,0 +152,0 @@ }

{
"/models/small": {
"chunks": {
"7001d60734fdc112dd9c062635fb59cd401fb82a9d4213134bce4dbd655c803a": {
"range": [
0,
44342435
]
"chunks": [
{
"hash": "b34a3e9350ad77140964b6a2e1e32cd9738acd9d01e5899b96be71901a22ef47",
"offset": 0,
"size": 4194304
},
{
"hash": "8a85c22e472bed10198298a3d57480a5a90946dba88bddecf8b0bf0eafc06e70",
"offset": 4194304,
"size": 4194304
},
{
"hash": "5faec25d2338ae8ca2c7bff72e954cebd40a04c5f34c4b6bb8ca6720fae40996",
"offset": 8388608,
"size": 4194304
},
{
"hash": "b9861d932a549be455fc8ebd8ce5d413049515bfdd3edd55e136dbe05dd34ef5",
"offset": 12582912,
"size": 4194304
},
{
"hash": "f070b4c4f512cfe8dd6936c3cb9a616f132894867d3d33304d83599eb6b55636",
"offset": 16777216,
"size": 4194304
},
{
"hash": "10d02652d10fbc47bf93732ff9e8ad53eefbd3bd89ab3c1fbc15ddd740bea672",
"offset": 20971520,
"size": 4194304
},
{
"hash": "014c9e0229363137e92b85ed3c6f56b1386c279cdd9af2d7f1960ed8428b5e94",
"offset": 25165824,
"size": 4194304
},
{
"hash": "34dd3ad760f7e31b5e9144b8c387b8ecd6dc43116248c93c56dd7051ab525e3b",
"offset": 29360128,
"size": 4194304
},
{
"hash": "e7ca5cc3e0afd65581642a05ac91eb8ea4d0deb868df94b8981c910212526476",
"offset": 33554432,
"size": 4194304
},
{
"hash": "0ad4ebb86cfdd847901427181b7a7804dba93d868c3cd5f11a294acf36c9413f",
"offset": 37748736,
"size": 4194304
},
{
"hash": "9582c0375aed822c5577a814766c4afc6c096f4ccd3b0d08af6a1794987206a1",
"offset": 41943040,
"size": 2399396
}
},
],
"size": 44342436,

@@ -15,10 +64,114 @@ "mime": "application/octet-steam"

"/models/medium": {
"chunks": {
"b6e8497ba978a6f5fbb647e419d2696cd80df5a23cb6a8ea532021911bd76acb": {
"range": [
0,
88188478
]
"chunks": [
{
"hash": "fe1b9f06af9d2147016884f4eb683d4dc540244a7453c3b742ae527725df2eec",
"offset": 0,
"size": 4194304
},
{
"hash": "724543b36c7b5eddfbd7f55cb5a7c1676b2089c277611850c257efa42212d8a2",
"offset": 4194304,
"size": 4194304
},
{
"hash": "f9290547b2e34555536647c1e2ca456348170eef1aee05d8fd522f5a051f260c",
"offset": 8388608,
"size": 4194304
},
{
"hash": "897d4d8a3f9f8c07f439300a5d81c8be4b0fcecf19ca6d77929b1750fedd8306",
"offset": 12582912,
"size": 4194304
},
{
"hash": "cbcda0a0c830ba51928e7935d9d3cfe1c4dc258bf117f2c76d047113ab8f9f8c",
"offset": 16777216,
"size": 4194304
},
{
"hash": "4c44c8b64af9f044623ceace7cc55e0bc348394f7ff63629d46118c0a03c9c54",
"offset": 20971520,
"size": 4194304
},
{
"hash": "8b2e3d773d7084c5cfac1c04d69d3586e4b8914a840d2b582dfde4940d698957",
"offset": 25165824,
"size": 4194304
},
{
"hash": "024e3d8beaf517d25496b73e36b0e0498110652753273e0dd8b591ad7c1c9e2f",
"offset": 29360128,
"size": 4194304
},
{
"hash": "1b8eaad4cd019b76e7eba964a38711a0bdeafbd10b6208c1107403a64dbd902a",
"offset": 33554432,
"size": 4194304
},
{
"hash": "0c8c5c24237304482ccc70a50008b73c8ef53e4656068da32b635607cca0c8c9",
"offset": 37748736,
"size": 4194304
},
{
"hash": "a5b8c519c832bc46b2ae5a9887fac1e3d5cc76a04846d8c3544875c7f2b40960",
"offset": 41943040,
"size": 4194304
},
{
"hash": "7b1dd767c5c1c0156b8d13bb34d4c1d11e014723b10cddc25c93e89a28e7cd96",
"offset": 46137344,
"size": 4194304
},
{
"hash": "3f5638267419916c9d4d906ff25f721d3d2e034851ea01566f0d2d6f943550b8",
"offset": 50331648,
"size": 4194304
},
{
"hash": "9927e74b3a0638d4cf5701e78e66d77476a4ba68c75831f1c8ea9117ec7f8809",
"offset": 54525952,
"size": 4194304
},
{
"hash": "3315eb3c14ca3ff5c03c80fac58f486a14264dd0bb9c168c096f2bd2531ba438",
"offset": 58720256,
"size": 4194304
},
{
"hash": "230f667e0332dc09ef08aacbf1992c40ce112192f95dfc14231a3ef515f9a2c7",
"offset": 62914560,
"size": 4194304
},
{
"hash": "e01a157b677e0e17815cd738dcda7e6daa268898d006b52b5d3604c439e6c96e",
"offset": 67108864,
"size": 4194304
},
{
"hash": "529f1df7d027b0315090ba15d42ef32998cac2efd6783c62f6b11cedf4c548f3",
"offset": 71303168,
"size": 4194304
},
{
"hash": "6cfd013f552a05e9fc81156e6d6de593668e0247a3970feae22e285c16d13e62",
"offset": 75497472,
"size": 4194304
},
{
"hash": "3f31511c3c16a29cf81b32379f51ead2bd082677b48b1dcc11a66beeb37cc729",
"offset": 79691776,
"size": 4194304
},
{
"hash": "01f6efcc8a01c727d99073ceede8e64c654fa3c4612b006e69e22dc663236943",
"offset": 83886080,
"size": 4194304
},
{
"hash": "145d8355f50b7847de5d04815124790867fe1752a0013bdf6ce28882b5e0a2fc",
"offset": 88080384,
"size": 108095
}
},
],
"size": 88188479,

@@ -28,73 +181,147 @@ "mime": "application/octet-steam"

"/onnxruntime-web/ort-wasm.wasm": {
"chunks": {
"0ee8126744a713debb3b0fc1e041d56755514cd764fd1e10496b3a3b7183cf20": {
"range": [
0,
9859591
]
"chunks": [
{
"hash": "ec4fed85437428b2a9bb00e3520632e80c1025d977d97252f5992bb6e3837ff7",
"offset": 0,
"size": 4194304
},
{
"hash": "4bae6253de7c3c2261b8c58168215ac62570b1d76f495f664f152712422158c0",
"offset": 4194304,
"size": 4194304
},
{
"hash": "35b512e28d3397aad6fe08e668c746fc0ccb290abd5b081ad3ea89595c8e2ed0",
"offset": 8388608,
"size": 1543196
}
},
"size": 9859592,
],
"size": 9931804,
"mime": "application/wasm"
},
"/onnxruntime-web/ort-wasm-threaded.wasm": {
"chunks": {
"08f7410781ecce25e040e5868b95f27ae76c18d6b957006fc6a4e65dc9fd1ba6": {
"range": [
0,
9799030
]
"chunks": [
{
"hash": "c918eed454a47bb07594f250a8f245493b3cb73f3ab2345f6403df2cff245c9c",
"offset": 0,
"size": 4194304
},
{
"hash": "9c79f200867a1a58b782e875d87b1a959b029935460acc8328421c75df2e841a",
"offset": 4194304,
"size": 4194304
},
{
"hash": "5fa9533ffa0bcdf6563b07f2caee49686a3217da9b253a2b65653418ea41cf84",
"offset": 8388608,
"size": 1479749
}
},
"size": 9799031,
],
"size": 9868357,
"mime": "application/wasm"
},
"/onnxruntime-web/ort-wasm-simd.wasm": {
"chunks": {
"3a52aac4a0ac9713ac3afa8902aba2059fd4f7ea1fa7cd7da74ac23b2567fb45": {
"range": [
0,
10839664
]
"chunks": [
{
"hash": "c77165be7e08590aa9c9b429e6fe0fb226d7c8116ae3437475525e577e8dca6e",
"offset": 0,
"size": 4194304
},
{
"hash": "6c02da2d5439fe6ebbcfc19d2b2ec0cb427446301534940ea97379be43d5b8ef",
"offset": 4194304,
"size": 4194304
},
{
"hash": "f011d7da3defcd6e416b0680543a137e45268ca3a7246d2292175aa31a36f2d5",
"offset": 8388608,
"size": 2524122
}
},
"size": 10839665,
],
"size": 10912730,
"mime": "application/wasm"
},
"/onnxruntime-web/ort-wasm-simd.jsep.wasm": {
"chunks": {
"3c5c9e3fe8454c348196ebcad33796794c319cb2ea46da13b71842eee77a6630": {
"range": [
0,
17700400
]
"chunks": [
{
"hash": "fc245094ef57bfc331d5d9ac813ab98993982cc9e1dbf379433292213b88bfbe",
"offset": 0,
"size": 4194304
},
{
"hash": "c07241f742bba34926db52ab955e70dac7a06b411dd938cc21dde21a89935417",
"offset": 4194304,
"size": 4194304
},
{
"hash": "01a92dae96b9eb2fc59a9236cfb508e850fe700640c0fc74d97b5c511ce704fd",
"offset": 8388608,
"size": 4194304
},
{
"hash": "fec9dd05587ba8f70f4a29adb6767832a7611ab0cc927079ad10c55abaf81966",
"offset": 12582912,
"size": 4194304
},
{
"hash": "0b46adac4f0ab6b630c71b79aca902d54b6a5da11b9dc93063fc122a378e1992",
"offset": 16777216,
"size": 1049008
}
},
"size": 17700401,
],
"size": 17826224,
"mime": "application/wasm"
},
"/onnxruntime-web/ort-wasm-simd-threaded.wasm": {
"chunks": {
"1f2b6dd15bd056a9f7965974fe15e2858e5373b94a02768b7c4e5b72aa456577": {
"range": [
0,
10797935
]
"chunks": [
{
"hash": "d057c2fe2a663ea72e227dbc1b7bb29a9536118193c84378daeec144ffd0876b",
"offset": 0,
"size": 4194304
},
{
"hash": "15bc58d07f1755729c178f427b971932a156bfa881888fdd0e9b5a05615d23c2",
"offset": 4194304,
"size": 4194304
},
{
"hash": "9e0fe1849a784328c64cc84f253ffb2ef834d8c3002c111baccb7a3ed9ec5469",
"offset": 8388608,
"size": 2479381
}
},
"size": 10797936,
],
"size": 10867989,
"mime": "application/wasm"
},
"/onnxruntime-web/ort-wasm-simd-threaded.jsep.wasm": {
"chunks": {
"4a4217bf6cab4d3acee30c5ab57765b9ec7ba4986afa2ba76307f844b8a3dfd2": {
"range": [
0,
19348757
]
"chunks": [
{
"hash": "9fa089154fa21f45aa5bb4d4f3f18217ba9917248c6acdcc86f138806aad0253",
"offset": 0,
"size": 4194304
},
{
"hash": "22b2e4f188dd5a9ce0bd5f49ba6e0776803ff92233fe911ab3eefaaaaad2a73d",
"offset": 4194304,
"size": 4194304
},
{
"hash": "aa3c82db95225211d95855161d0590235c5117f1cf7da20f7ede22520d8975b9",
"offset": 8388608,
"size": 4194304
},
{
"hash": "abd9829fec6309c91362091ffffc33c5abb258faf44b6cc7c857cb455256a023",
"offset": 12582912,
"size": 4194304
},
{
"hash": "30488a20752335633069be78f6c980fae93117c8c00f49ec48cfccc20ab747c1",
"offset": 16777216,
"size": 2719142
}
},
"size": 19348758,
],
"size": 19496358,
"mime": "application/wasm"
}
}
{
"name": "@imgly/background-removal",
"version": "1.2.1",
"version": "1.3.0",
"description": "Background Removal in the Browser",

@@ -62,3 +62,3 @@ "keywords": [

"ndarray": "^1.0.19",
"onnxruntime-web": "^1.16.0",
"onnxruntime-web": "^1.16.3",
"zod": "^3.21.4"

@@ -79,2 +79,2 @@ },

}
}
}

@@ -12,7 +12,2 @@ # Background Removal in the Browser

- **`November 8th, 2023`:** Added support for raw `rgba8` export formats.
- **`November 6th, 2023`:** Added support `foreground`, `background` and `mask` export type
- **`November 6th, 2023`:** Added support for `webp` and `jpeg` export formats.
- **`June 28th, 2023`:** We released the code of Background Removal JS for Web.
For more detail information please refer to the [CHANGELOG](./CHANGELOG.md).

@@ -65,3 +60,3 @@

type Config = {
publicPath: string; // The public path used for model and wasm files
publicPath: string; // The public path used for model and wasm files. Default: 'https://unpkg.com/${PACKAGE_NAME}@${PACKAGE_VERSION}/dist/'
debug: bool; // enable or disable useful console.log outputs

@@ -68,0 +63,0 @@ proxyToWorker: bool; // Whether to proxy the calculations to a web worker. (Default true)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc