• Remove background from an image and return as HTMLCanvasElement.

    Similar to the remove() function but returns a canvas instead of a blob. This is useful when you need to perform additional canvas operations or want to avoid the blob conversion overhead.

    Parameters

    • data: HTMLImageElement | HTMLCanvasElement | File | Blob | ArrayBuffer

      Input image as File, Blob, ArrayBuffer, HTMLImageElement, or HTMLCanvasElement

    • options: RemoveOptions = {}

      Processing options

    Returns Promise<HTMLCanvasElement>

    Promise - Processed image as canvas with transparent background

    Example

    // Get canvas for further processing
    const canvas = await removeToCanvas(file);
    const ctx = canvas.getContext('2d');
    // Perform additional canvas operations...

    // Convert to blob when ready
    const blob = await new Promise(resolve =>
    canvas.toBlob(resolve, 'image/png')
    );

    Throws

    When input type is not supported

    Throws

    When model fails to generate masks

    Throws

    When browser doesn't support required features (WASM, IndexedDB, etc.)