Hello, guys In this tutorial we will try to solve the mentioned query. and also we will learn how to capture picture using JavaScript.
Common Query
- How to capture picture using JavaScript?
- How to capture a webcam image using JavaScript?
- How to draw a snapshot of a webcam in HTML?
For capturing pictures using JavaScript, first we need the Webcam JS library
See Also:- How to Integrate Webcam using JavaScript
What is webcam js?
Webcam.js is an Open Source JavaScript library that allows us to capture a picture from the webcam. It uses HTML5 getUserMedia API to capture the picture.
Webcam Js Quick Start Guide
We need to host the webcam.js
and webcam.swf
files on your web server, and drop in this HTML snippet:
<script src="webcam.js"></script>
<div id="camera"></div>
<div id="snapShot"></div>
<script language="JavaScript">
Webcam.attach( '#camera' );
takeSnapShot = function() {
Webcam.snap(function(data_uri) {
document.getElementById('snapShot').innerHTML =
'<img src=" ' +data_uri+' " width="400" height="400">';
})
}
</script>
<input type="button" value="" id="cameraBtn" onclick="takeSnapShot()">
This will create a live camera view in the #camera
DIV, and when the Take Snapshot link is clicked it will take a still snapshot, convert it to a JPEG, and deliver a Data URI which is inserted into the #snapShot
DIV as a standard <img>
tag.
Webcam Js Configuration
If you want to change the default settings, just call Webcam.set()
and pass in a hash with any of the following keys:
Height : Auto
Width : Auto
dest_width : Auto
dest_height : Auto
crop_width : Disabled
crop_height : Disabled
image_format : jpeg
force_flash : false
jpeg_quality : 90
I will show you an example of overriding some parameters. Remember to call this before you attach the viewer.
Webcam.set({
width:650,
height:310,
dest_width: 1300,
dest_height: 620,
image_format: 'jpeg',
jpeg_quality: 90,
force_flash: false
});
Capture picture using JavaScript Video Output
Top comments (4)
Webcam JS is in maintenance mode and the library linked to my the author of webcamjs is no longer maintained.
Recommending either of these libraries isn't good.
Thanks, You're Right
Check more info about Webcam Js
getting the webcam these days is a lot easier than it used to be (with the exception of IE11, which doesn't have webcam features enabled without flash).
To get a webcam stream you can do
but flash is dead