rn-remove-image-bg 0.0.18 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ImageProcessing.web.js +13 -12
- package/package.json +1 -1
- package/src/ImageProcessing.web.ts +13 -12
|
@@ -14,15 +14,15 @@ const WORKER_CODE = `
|
|
|
14
14
|
|
|
15
15
|
try {
|
|
16
16
|
if (type === 'init') {
|
|
17
|
-
if (!removeBackground) {
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
if (typeof self.imglyBackgroundRemoval === 'undefined' || !removeBackground) {
|
|
18
|
+
// Use importScripts (Classic Worker) - most robust for Blob URLs
|
|
19
|
+
importScripts('https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.7.0/dist/imgly-background-removal.min.js');
|
|
20
|
+
|
|
21
|
+
if (!self.imglyBackgroundRemoval) {
|
|
22
|
+
throw new Error('imglyBackgroundRemoval not loaded via importScripts');
|
|
23
|
+
}
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
// Unless we want to preload the wasm.
|
|
25
|
-
// self.postMessage({ id, type: 'progress', payload: { progress: 0.1 } });
|
|
25
|
+
removeBackground = self.imglyBackgroundRemoval.removeBackground;
|
|
26
26
|
}
|
|
27
27
|
self.postMessage({ id, type: 'success', payload: true });
|
|
28
28
|
return;
|
|
@@ -32,15 +32,16 @@ const WORKER_CODE = `
|
|
|
32
32
|
const { uri, config } = payload;
|
|
33
33
|
|
|
34
34
|
if (!removeBackground) {
|
|
35
|
-
|
|
36
|
-
removeBackground =
|
|
35
|
+
importScripts('https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.7.0/dist/imgly-background-removal.min.js');
|
|
36
|
+
removeBackground = self.imglyBackgroundRemoval.removeBackground;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// Run Inference
|
|
40
|
-
//
|
|
40
|
+
// CRITICAL: Must point publicPath to CDN so it finds WASM/Models
|
|
41
|
+
// otherwise it tries to load from blob: URL
|
|
41
42
|
const blob = await removeBackground(uri, {
|
|
43
|
+
publicPath: 'https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.7.0/dist/',
|
|
42
44
|
progress: (key, current, total) => {
|
|
43
|
-
// Map progress roughly
|
|
44
45
|
const p = current / total;
|
|
45
46
|
self.postMessage({ id, type: 'progress', payload: { progress: p } });
|
|
46
47
|
},
|
package/package.json
CHANGED
|
@@ -24,15 +24,15 @@ const WORKER_CODE = `
|
|
|
24
24
|
|
|
25
25
|
try {
|
|
26
26
|
if (type === 'init') {
|
|
27
|
-
if (!removeBackground) {
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
if (typeof self.imglyBackgroundRemoval === 'undefined' || !removeBackground) {
|
|
28
|
+
// Use importScripts (Classic Worker) - most robust for Blob URLs
|
|
29
|
+
importScripts('https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.7.0/dist/imgly-background-removal.min.js');
|
|
30
|
+
|
|
31
|
+
if (!self.imglyBackgroundRemoval) {
|
|
32
|
+
throw new Error('imglyBackgroundRemoval not loaded via importScripts');
|
|
33
|
+
}
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
// Unless we want to preload the wasm.
|
|
35
|
-
// self.postMessage({ id, type: 'progress', payload: { progress: 0.1 } });
|
|
35
|
+
removeBackground = self.imglyBackgroundRemoval.removeBackground;
|
|
36
36
|
}
|
|
37
37
|
self.postMessage({ id, type: 'success', payload: true });
|
|
38
38
|
return;
|
|
@@ -42,15 +42,16 @@ const WORKER_CODE = `
|
|
|
42
42
|
const { uri, config } = payload;
|
|
43
43
|
|
|
44
44
|
if (!removeBackground) {
|
|
45
|
-
|
|
46
|
-
removeBackground =
|
|
45
|
+
importScripts('https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.7.0/dist/imgly-background-removal.min.js');
|
|
46
|
+
removeBackground = self.imglyBackgroundRemoval.removeBackground;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// Run Inference
|
|
50
|
-
//
|
|
50
|
+
// CRITICAL: Must point publicPath to CDN so it finds WASM/Models
|
|
51
|
+
// otherwise it tries to load from blob: URL
|
|
51
52
|
const blob = await removeBackground(uri, {
|
|
53
|
+
publicPath: 'https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.7.0/dist/',
|
|
52
54
|
progress: (key, current, total) => {
|
|
53
|
-
// Map progress roughly
|
|
54
55
|
const p = current / total;
|
|
55
56
|
self.postMessage({ id, type: 'progress', payload: { progress: p } });
|
|
56
57
|
},
|