aboutsummaryrefslogtreecommitdiff
path: root/src/workers/image.worker.ts
blob: c6db44d03be3957e2af87ea96730e6206eb7b58d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { removeBackground } from '@imgly/background-removal';

self.onmessage = async (event: MessageEvent) => {
    const { imagePath, options, nativeWidth, nativeHeight, docId } = event.data;

    try {
        // Perform the background removal
        const result = await removeBackground(imagePath);

        // Send the result back to the main thread
        self.postMessage({ success: true, result, options, nativeWidth, nativeHeight, docId });
    } catch (error) {
        // Send the error back to the main thread
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        self.postMessage({ success: false, error: (error as any).message });
    }
};