Svelte

Accura Face Plugin — Svelte Integration Guide

This guide walks you through integrating the Accura Face Plugin into a Svelte project built with Vite.


Prerequisites

Before proceeding, ensure the following requirement is met:

  • accura.xml — Place your accura.xml license file in the public/ folder (Vite) or static/ folder (SvelteKit) as public/accura.xml or static/accura.xml respectively. This file is required by the plugin to initialize the face detection engine. You can download it from here.

941KB
Open

Step 1: Initialize Project

If you do not have an existing Svelte project, scaffold one using Vite:

npm create vite@latest my-face-app -- --template svelte
cd my-face-app
npm install

Step 2: Install Plugin

Install the Accura Face Plugin package from the npm registry:


Step 3: Implementation

Create a dedicated scanner component at src/lib/FaceScanner.svelte. The following snippet shows only the plugin import and initialization logic:


Step 4: Response Handling

When the plugin captures a valid face, it invokes the base64Handler callback with an object containing a base64 property — a Data URL string representing the captured face image encoded in Base64 format (e.g., data:image/jpeg;base64,/9j/...).

What is Base64? Base64 is a binary-to-text encoding scheme that converts raw binary image data into a sequence of printable ASCII characters. The prefix segment (e.g., data:image/jpeg;base64,) conveys the MIME type, while the remainder is the encoded image payload. This format enables seamless transmission of binary content over text-based HTTP protocols without requiring binary transport mechanisms.

The following handler demonstrates forwarding the captured image to a remote verification endpoint:


Step 5: Demo Implementation

The following is the complete, production-ready component. Copy and paste it directly into src/lib/FaceScanner.svelte. The original logic is preserved exactly as-is.


Step 6: Usage

Import and render the component in App.svelte:


Step 7: Running the Project

Last updated