Skip to content
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 Blob with capture, shows it, and releases the camera, so its light goes off. Retake starts the camera again.
  • facing chooses the camera to start with: user (default) faces the person, and environment faces 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.
  • type sets the image type (default image/jpeg), and quality sets 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 error sends the reason.
  • The camera needs a secure page (HTTPS or localhost).
  • Change the words with labels or a label pack: the buttons, preview, photo (the alternative text of the photo), and unavailable.

Usage ​

ts
import { BlessCameraCapture } from "blessing-ui";

API ​

Props

NameTypeDefaultDescription
facing"user" | "environment""user"the camera to start with: `user` faces the person, `environment` faces away
typestring"image/jpeg"the image type of the photo
qualitynumber0.90 to 1, for `image/jpeg` and `image/webp`
labelsPartial<{ start: string; capture: string; switch: string; retake: string; preview: string; photo: string; unavailable: string; }>—

Events

NamePayloadDescription
error[error: unknown]
capture[photo: Blob]

Released under the MIT License. Character names and artwork belong to their owners.