Sunday, June 18, 2017

Webcam Image Capture

This is example for capturing image and save it to any location using webcam.js.


<!doctype html>

<html lang="en">
<head>
<title>camera image</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; }
</style>
<script type="text/javascript" src="webcam.js"></script>
</head>
<body>
<div id="results">Captured Image</div>
<div id="my_camera"></div>
<input type=button value="Take Snapshot" onClick="take_snapshot()">
</body>
</html>
<script language="JavaScript">
Webcam.set({
width: 200,
height: 250,
image_format: 'jpeg',
jpeg_quality: 90
});
Webcam.attach( '#my_camera' );
function take_snapshot() {
// take snapshot and get image data
Webcam.snap( function(data_uri) {
// display results in page

document.getElementById('results').innerHTML =
'<h2>Processing:</h2>';

Webcam.upload( data_uri, 'saveimage.php', function(code, text) {
document.getElementById('results').innerHTML =
'<h2>Here is your image:</h2>' +
'<img src="'+text+'"/>';
} );
} );
}
</script>

saveimage.php
<?php
$filename =  time() . '.jpg';
$filepath = 'saved_images/';

move_uploaded_file($_FILES['webcam']['tmp_name'], $filepath.$filename);

echo $filepath.$filename;

?>


ref:http://theonlytutorials.com/capture-web-camera-image-php-jquery/

No comments:

Post a Comment