Skip to content

Instantly share code, notes, and snippets.

@anantn
Created February 17, 2012 09:12
Show Gist options
  • Select an option

  • Save anantn/1852070 to your computer and use it in GitHub Desktop.

Select an option

Save anantn/1852070 to your computer and use it in GitHub Desktop.
Take a picture with getUserMedia
<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>
@HortenciaPortes
Copy link
Copy Markdown

thank you so much help me a lot

@Vuurvlieg
Copy link
Copy Markdown

@TobiasSeitz @jan-ivar Thank you so much, this will help me a lot!

@Magistern
Copy link
Copy Markdown

Do you know how to make this work on iOS 11.3?
I know Instagram.com makes it work somehow.

@kimpossible6
Copy link
Copy Markdown

thanks so much!!

@barcenitas
Copy link
Copy Markdown

I love you

@TudorGruian
Copy link
Copy Markdown

Thank you so much.Really apreciate it

@ubonsoft
Copy link
Copy Markdown

ubonsoft commented Jun 5, 2018

So GOOOOOOD

@regisnew
Copy link
Copy Markdown

regisnew commented Sep 3, 2018

Show.
Congrants.

@dgloriaweb
Copy link
Copy Markdown

Sorry guys for me being lame, but where does canvas.toDataURL save the image? Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment