mighty-webcamjs
Version:
HTML5 Webcam Image Capture Library with Flash Fallback
98 lines (87 loc) • 2.41 kB
HTML
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>WebcamJS Test Page</title>
<style type="text/css">
body { font-family: Helvetica, sans-serif; }
h2, h3 { margin-top:0; }
form { margin-top: 15px; }
form > input { margin-right: 15px; }
#results { float:right; margin:20px; padding:20px; border:1px solid; background:#ccc; }
.webcamjs__upload-fallback {
text-align: center;
width: 100%;
height: 100%;
position: relative;
}
.webcamjs__upload-fallback input {
width: 100%;
height: 100%;
cursor: pointer;
}
.webcamjs__upload-fallback:after {
content: 'Click to select picture';
pointer-events: none;
position: absolute;
top: 0;
left: 0;
width: 100%;
color: #FFF;
text-align: center;
line-height: 2em;
}
.webcamjs__upload-fallback:before {
content: '';
background: #666 url("./fa-cloud-upload.svg") no-repeat center center;
background-size: 50%;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
pointer-events: none;
}
</style>
</head>
<body>
<div id="results">Your captured image will appear here...</div>
<h1>WebcamJS Test Page</h1>
<h3>Demonstrates File Upload capture & display</h3>
<div id="my_camera"></div>
<!-- First, include the Webcam.js JavaScript Library -->
<script type="text/javascript" src="../webcam.dist.js"></script>
<!-- Configure a few settings and attach camera -->
<script language="JavaScript">
Webcam.set({
width: 320,
height: 240,
dest_width: 320,
dest_height: 240,
force_file: true,
image_format: 'jpeg',
jpeg_quality: 90,
webcam_path: '../'
});
Webcam.attach( document.querySelector('#my_camera') );
</script>
<!-- A button for taking snaps -->
<form>
<input type=button value="Take Snapshot" onClick="take_snapshot()">
</form>
<!-- Code to handle taking the snapshot and displaying it locally -->
<script language="JavaScript">
function take_snapshot() {
// take snapshot and get image data
Webcam.snap().then( function(data_uri) {
// display results in page
document.getElementById('results').innerHTML =
'<h2>Here is your image:</h2>' +
'<img src="'+data_uri+'"/>';
} );
}
// This line allows to trigger "snap" right after selecting file.
Webcam.on('imageSelected', take_snapshot);
</script>
</body>
</html>