Calm motion: animations on this site only fade, with no movement
CameraCapture
Take a photo with the camera, in the page
Takes a photo for a profile, a receipt, or a document, with getUserMedia and a canvas. People see the camera in the page and can take the photo again. If a phone's own camera app is enough, use a file input with accept="image/*" and capture instead, which needs no code. To crop the photo after, use the cropper.
Basic
- Start camera asks for the camera. The browser asks for permission only then, not when the page opens.
- Take photo sends the photo as a
Blobwithcapture, shows it, and releases the camera, so its light goes off. Retake starts the camera again. facingchooses the camera to start with:user(default) faces the person, andenvironmentfaces away. When the device has more than one camera, Switch camera shows.- The front camera shows as a mirror, as people expect from a mirror. The photo itself is not mirrored, so text in it reads correctly.
typesets the image type (defaultimage/jpeg), andqualitysets the quality from 0 to 1 (default 0.9). The photo has the full size of the camera image.- When there is no camera or no permission, a line says so, and
errorsends the reason. - The camera needs a secure page (HTTPS or
localhost). - Change the words with
labelsor a label pack: the buttons,preview,photo(the alternative text of the photo), andunavailable.
Usage
ts
import { BlessCameraCapture } from "blessing-ui";API
Props
| Name | Type | Default | Description |
|---|---|---|---|
facing | "user" | "environment" | "user" | the camera to start with: `user` faces the person, `environment` faces away |
type | string | "image/jpeg" | the image type of the photo |
quality | number | 0.9 | 0 to 1, for `image/jpeg` and `image/webp` |
labels | Partial<{ start: string; capture: string; switch: string; retake: string; preview: string; photo: string; unavailable: string; }> | — |
Events
| Name | Payload | Description |
|---|---|---|
error | [error: unknown] | |
capture | [photo: Blob] |