Selfie Playground
Configure the single-image selfie capture flow, launch it, and handle the captured image.
Overview
Selfie capture is the Headless SDK's single-image alternative to the two-photo Scanflow. When invoked, it embeds a guided, face-tracking camera interface that walks the user through capturing one selfie, then hands the image back to your code as a base64 JPEG you can pass straight to selfie estimation.
Unlike Scanflow, there is only one screen — the live capture view — and a smaller set of configuration options.
Implementation
Call sdk.selfie() to launch the capture flow. It returns a promise that resolves with the captured image and its dimensions once the user completes the capture.
const { image, width, height, capturedAt } = await sdk.selfie({
facingMode: 'user',
orientation: 'auto',
requireGyro: false,
isDebug: false,
});Configuration
All fields are optional.
| Option | Type | Default | Description |
|---|---|---|---|
facingMode | 'user' | 'environment' | 'user' | Which camera to open. Selfie defaults to the front-facing camera. |
orientation | 'auto' | 'portrait' | 'landscape' | 'auto' | Lock the capture orientation, or let the SDK pick based on the device. |
requireGyro | boolean | false | When true, the SDK requests DeviceOrientationEvent permission on iOS before starting. |
isDebug | boolean | false | Renders an on-screen overlay with face-tracking diagnostics. Useful during development. |
Selfie capture loads a face-tracking model on launch, so the first capture may take a moment longer than a regular camera open. The SDK shows its own loader while the model initialises.
Error handling
sdk.selfie() returns a promise that can reject in two cases:
| Code | When |
|---|---|
SELFIE_CLOSED_BY_USER | The user closed the capture UI before completing the selfie. |
INVALID_SELFIE_CAPTURE_PAYLOAD | The capture completed but returned data that failed validation. |
try {
const { image } = await sdk.selfie(config);
} catch (err) {
if (err.code === 'SELFIE_CLOSED_BY_USER') {
// user dismissed the capture UI
} else if (err.code === 'INVALID_SELFIE_CAPTURE_PAYLOAD') {
// unexpected payload from the selfie iframe
}
}Try it
Configure the options below and launch the selfie capture with your client key.
Interactive Demo
Selfie
API reference
Detailed signatures, parameters, and response shapes for everything used on this page live in the Headless SDK API reference.
Methods
selfie(config?)— open the selfie capture UI and resolve with the captured image as a base64 JPEG plus its dimensions.getBody2FitSelfieEstimation(params)— estimate body measurements from the captured selfie.
Initialization
new BodygramSDK({ clientKey, locale, ... })— construct the SDK before callingselfie().
