-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.js
More file actions
23 lines (20 loc) · 803 Bytes
/
Copy pathcamera.js
File metadata and controls
23 lines (20 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const video = document.getElementById("camera");
const captureBtn = document.getElementById("capture-img");
const imageTag = document.getElementById("image");
const mirror =
"-moz-transform: scale(-1, 1); \
-webkit-transform: scale(-1, 1); -o-transform: scale(-1, 1); \
transform: scale(-1, 1); filter: FlipH;";
captureBtn.addEventListener("click", () => {
const canvas = document.createElement("canvas");
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
canvas.getContext("2d").drawImage(video, 0, 0, canvas.width, canvas.height);
const dataURL = canvas.toDataURL();
imageTag.style.cssText = mirror;
imageTag.src = dataURL;
});
navigator.mediaDevices.getUserMedia({ video: true }).then((stream) => {
video.srcObject = stream;
video.style.cssText = mirror;
});