@imgly/background-removal
Advanced tools
Comparing version 1.1.5 to 1.2.0
@@ -5,3 +5,3 @@ declare module '@imgly/background-removal/src/codecs' { | ||
function imageDecode(blob: Blob): Promise<NdArray<Uint8Array>>; | ||
function imageEncode(imageTensor: NdArray<Uint8Array>, quality?: number, type?: string): Promise<Blob>; | ||
function imageEncode(imageTensor: NdArray<Uint8Array>, quality?: number, format?: string): Promise<Blob>; | ||
@@ -12,5 +12,6 @@ } | ||
export type { ImageSource, Config }; | ||
export { removeBackground }; | ||
export { removeBackground, preload }; | ||
import { Config } from '@imgly/background-removal/src/schema'; | ||
type ImageSource = ImageData | ArrayBuffer | Uint8Array | Blob | URL | string; | ||
function preload(configuration?: Config): Promise<void>; | ||
function removeBackground(image: ImageSource, configuration?: Config): Promise<Blob>; | ||
@@ -28,5 +29,10 @@ | ||
proxyToWorker?: boolean; | ||
fetchArgs?: {}; | ||
fetchArgs?: any; | ||
progress?: (args_0: string, args_1: number, args_2: number, ...args_3: unknown[]) => undefined; | ||
model?: "small" | "medium"; | ||
output?: { | ||
format?: "image/png" | "image/jpeg" | "image/webp"; | ||
quality?: number; | ||
type?: "background" | "mask" | "foreground"; | ||
}; | ||
}; | ||
@@ -48,4 +54,5 @@ session: import("onnxruntime-common").InferenceSession; | ||
declare module '@imgly/background-removal/src/resource' { | ||
export { loadAsBlob, loadAsUrl }; | ||
export { loadAsBlob, loadAsUrl, preload }; | ||
import { Config } from '@imgly/background-removal/src/schema'; | ||
function preload(config: Config): Promise<void>; | ||
function loadAsUrl(url: string, config: Config): Promise<string>; | ||
@@ -62,5 +69,18 @@ function loadAsBlob(key: string, config: Config): Promise<Blob>; | ||
proxyToWorker: z.ZodDefault<z.ZodBoolean>; | ||
fetchArgs: z.ZodDefault<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>; | ||
fetchArgs: z.ZodDefault<z.ZodAny>; | ||
progress: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodString, z.ZodNumber, z.ZodNumber], z.ZodUnknown>, z.ZodUndefined>>; | ||
model: z.ZodDefault<z.ZodEnum<["small", "medium"]>>; | ||
output: z.ZodDefault<z.ZodObject<{ | ||
format: z.ZodDefault<z.ZodEnum<["image/png", "image/jpeg", "image/webp"]>>; | ||
quality: z.ZodDefault<z.ZodNumber>; | ||
type: z.ZodDefault<z.ZodEnum<["foreground", "background", "mask"]>>; | ||
}, "strip", z.ZodTypeAny, { | ||
format?: "image/png" | "image/jpeg" | "image/webp"; | ||
quality?: number; | ||
type?: "background" | "mask" | "foreground"; | ||
}, { | ||
format?: "image/png" | "image/jpeg" | "image/webp"; | ||
quality?: number; | ||
type?: "background" | "mask" | "foreground"; | ||
}>>; | ||
}, "strip", z.ZodTypeAny, { | ||
@@ -70,5 +90,10 @@ publicPath?: string; | ||
proxyToWorker?: boolean; | ||
fetchArgs?: {}; | ||
fetchArgs?: any; | ||
progress?: (args_0: string, args_1: number, args_2: number, ...args_3: unknown[]) => undefined; | ||
model?: "small" | "medium"; | ||
output?: { | ||
format?: "image/png" | "image/jpeg" | "image/webp"; | ||
quality?: number; | ||
type?: "background" | "mask" | "foreground"; | ||
}; | ||
}, { | ||
@@ -78,8 +103,13 @@ publicPath?: string; | ||
proxyToWorker?: boolean; | ||
fetchArgs?: {}; | ||
fetchArgs?: any; | ||
progress?: (args_0: string, args_1: number, args_2: number, ...args_3: unknown[]) => undefined; | ||
model?: "small" | "medium"; | ||
output?: { | ||
format?: "image/png" | "image/jpeg" | "image/webp"; | ||
quality?: number; | ||
type?: "background" | "mask" | "foreground"; | ||
}; | ||
}>>; | ||
type Config = z.infer<typeof ConfigSchema>; | ||
function validateConfig(config?: Config): Config; | ||
function validateConfig(configuration?: Config): Config; | ||
@@ -86,0 +116,0 @@ } |
{ | ||
"name": "@imgly/background-removal", | ||
"version": "1.1.5", | ||
"version": "1.2.0", | ||
"description": "Background Removal in the Browser", | ||
@@ -54,5 +54,3 @@ "keywords": [ | ||
"dependencies": { | ||
"onnxruntime-web": "^1.16.0" | ||
}, | ||
"devDependencies": { | ||
"onnxruntime-web": "^1.16.0", | ||
"@types/lodash": "^4.14.195", | ||
@@ -62,3 +60,5 @@ "@types/node": "^20.3.1", | ||
"ndarray": "^1.0.19", | ||
"zod": "^3.21.4", | ||
"zod": "^3.21.4" | ||
}, | ||
"devDependencies": { | ||
"assert": "^2.0.0", | ||
@@ -76,2 +76,2 @@ "esbuild": "^0.18.18", | ||
} | ||
} | ||
} |
@@ -12,3 +12,5 @@ # Background Removal in the Browser | ||
- **`June 28th, 2023`:** We released the code of Background Removal JS. | ||
- **`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. | ||
@@ -64,2 +66,7 @@ ## Overview | ||
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") | ||
}; | ||
}; | ||
@@ -75,2 +82,16 @@ ``` | ||
### Preloading Assets | ||
Per default, assets are downloaded on demand. You might enforce downloading all assets at once at any time by preloading them: | ||
```typescript | ||
import removeBackground, { preload, Config } from '@imgly/background-removal'; | ||
const config: Configuration = ...; | ||
preload(config).then(() => { | ||
console.log("Asset preloading succeeded") | ||
}) | ||
``` | ||
### Download Progress Monitoring | ||
@@ -102,4 +123,3 @@ | ||
```shell | ||
cp node_modules/@imgly/background-removal/dist/*.wasm $PUBLIC_PATH | ||
cp node_modules/@imgly/background-removal/dist/*.onnx $PUBLIC_PATH | ||
cp node_modules/@imgly/background-removal/dist/* $PUBLIC_PATH | ||
``` | ||
@@ -147,2 +167,4 @@ | ||
### Fetch Args | ||
`fetchArgs` are passed as second parameters to the fetch function as described in [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch). | ||
@@ -149,0 +171,0 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
11
187
9
210998393
6
1295
+ Added@types/lodash@^4.14.195
+ Added@types/node@^20.3.1
+ Addedlodash@^4.17.21
+ Addedndarray@^1.0.19
+ Addedzod@^3.21.4
+ Added@types/lodash@4.17.15(transitive)
+ Added@types/node@20.17.19(transitive)
+ Addediota-array@1.0.0(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedndarray@1.0.19(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addedzod@3.24.2(transitive)
- Removed@types/node@22.13.4(transitive)
- Removedundici-types@6.20.0(transitive)