-
Notifications
You must be signed in to change notification settings - Fork 0
/
webcam.html
39 lines (35 loc) · 1.16 KB
/
webcam.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE html>
<html lang="en">
<head>
<title>WEBC@M TEST</title>
</head>
<body>
<a><img /></a>
<script type="text/javascript" src="webcam.js"></script>
<script type="text/javascript">
var success = function(video, canvas, stream) {
var link = document.querySelector('a');
link.parentNode.insertBefore(video, link);
video.addEventListener('click', function(e) {
var width = this.videoWidth;
var height = this.videoHeight;
var img = document.querySelector('img');
canvas.setAttribute('width', width);
canvas.setAttribute('height', height);
canvas.getContext('2d').drawImage(video, 0, 0);
img.setAttribute('src', canvas.toDataURL('image/png'));
link.setAttribute('href', canvas.toDataURL('image/png'));
link.setAttribute('download', 'webcam.png');
});
video.play();
}
var failure = function(e) {
console.log("Stream failed", e);
}
var notsupported = function() {
console.log("Browser not supported");
}
webcam(success, failure, notsupported);
</script>
</body>
</html>