I want to Automatically take a picture from a webcam source, as soon as webcam access is granted from the browser, then save it to files, with no user input.
I have got the picture capturing sorted but i cannot:
A) Get it to automatically take the picture
B) Save the picture
The idea is that then there will be input for user email, then picture file will be renamed to their email.
This is what I have got so far:
<html>
<head>
</head>
<body>
<video id="player" controls autoplay></video>
<button id="capture">Capture</button>
<canvas id="canvas" width="320" height="240"></canvas>
<script>
const player = document.getElementById('player');
const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');
const captureButton = document.getElementById('capture');
const constraints = {
video: true,
};
captureButton.addEventListener('click', () => {
// Draw the video frame to the canvas.
context.drawImage(player, 0, 0, canvas.width, canvas.height);
});
// Attach the video stream to the video element and autoplay.
navigator.mediaDevices.getUserMedia(constraints).then((stream) => {
player.srcObject = stream;
});
</script>
</html>
So i just need to: A) Get it to automatically take the picture B) Save the picture