The takePhoto() method of the ImageCapture interface takes a single exposure using the video capture device sourcing a MediaStreamTrack and returns a Promise that resolves with a Blob containing the data.
takePhoto() takePhoto(photoSettings)
photoSettings OptionalAn object that sets options for the photo to be taken. The available options are:
fillLightModeThe flash setting of the capture device, one of "auto", "off", or "flash".
imageHeightThe desired image height as an integer. The user agent selects the closest height value to this setting if it only supports discrete heights.
imageWidthThe desired image width as an integer. The user agent selects the closest width value to this setting if it only supports discrete widths.
redEyeReductionA boolean indicating whether the red-eye reduction should be used if it is available.
A Promise that resolves with a Blob.
InvalidStateError DOMException
Thrown if readyState property of the MediaStreamTrack passing in the constructor is not live.
UnknownError DOMException
Thrown if the operation can't complete for any reason.
This example is extracted from this Simple Image Capture demo. It shows how to use the Promise returned by takePhoto() to copy the returned Blob to an <img> element. For simplicity it does not show how to instantiate the ImageCapture object.
let takePhotoButton = document.querySelector("button#takePhoto");
let canvas = document.querySelector("canvas");
takePhotoButton.onclick = takePhoto;
function takePhoto() {
imageCapture
.takePhoto()
.then((blob) => {
console.log("Took photo:", blob);
img.classList.remove("hidden");
img.src = URL.createObjectURL(blob);
})
.catch((error) => {
console.error("takePhoto() error: ", error);
});
}
| Specification |
|---|
| MediaStream Image Capture> # dom-imagecapture-takephoto> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
takePhoto |
6059–60photoSettings parameter not supported. |
79 | 35 | 4746–47photoSettings parameter not supported. |
18.4 | 6059–60photoSettings parameter not supported. |
No | 4443–44photoSettings parameter not supported. |
18.4 | 8.07.0–8.0photoSettings parameter not supported. |
6059–60photoSettings parameter not supported. |
18.4 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture/takePhoto