public
Last active

Take a picture with getUserMedia

  • Download Gist
getusermedia_picture.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<html>
<body>
<video id="v" width="300" height="300"></video>
<input id="b" type="button" disabled="true" value="Take Picture"></input>
<canvas id="c" style="display:none;" width="300" height="300"></canvas>
</body>
<script>
navigator.getUserMedia({video: true}, function(stream) {
var video = document.getElementById("v");
var canvas = document.getElementById("c");
var button = document.getElementById("b");
 
video.src = stream;
button.disabled = false;
button.onclick = function() {
canvas.getContext("2d").drawImage(video, 0, 0, 300, 300, 0, 0, 300, 300);
var img = canvas.toDataURL("image/png");
alert("done");
};
}, function(err) { alert("there was an error " + err)});
</script>
</html>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.