Last active
August 29, 2015 14:11
-
-
Save neogeek/2fd6e595e21789d7851e to your computer and use it in GitHub Desktop.
webcam-photo-capture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="initial-scale=1"> | |
<title>Webcam Photo Capture</title> | |
<style> | |
* { | |
margin: 0; padding: 0; | |
-webkit-box-sizing: border-box; | |
-moz-box-sizing: border-box; | |
box-sizing: border-box; | |
} | |
body { | |
margin: 1em; | |
font-family: 'Helvetica', 'Arial', sans-serif; | |
font-size: 1em; | |
line-height: 1.3em; | |
} | |
h1 { | |
font-weight: normal; | |
line-height: 1.3em; | |
} | |
a { | |
color: #00f; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Webcam Photo Capture</h1> | |
<video width="640" height="480" autoplay></video> | |
<canvas width="640" height="480"></canvas> | |
<img width="640" height="480" /> | |
<script src="/socket.io/socket.io.js"></script> | |
<script> | |
/*jslint browser: true */ | |
/*globals io*/ | |
(function () { | |
'use strict'; | |
var socket = io(); | |
navigator.webkitGetUserMedia({ video: true }, function (stream) { | |
var video = document.querySelector('video'), | |
canvas = document.querySelector('canvas'), | |
context = canvas.getContext('2d'), | |
image = document.querySelector('img'); | |
video.src = window.URL.createObjectURL(stream); | |
setInterval(function () { | |
context.drawImage(video, 0, 0, canvas.width, canvas.height); | |
image.setAttribute('src', canvas.toDataURL('image/jpeg', 100)); | |
socket.emit('image', canvas.toDataURL('image/jpeg', 100)); | |
}, 100); | |
}, function (error) { | |
console.log(error); | |
}); | |
}()); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "webcam-photo-capture", | |
"version": "0.0.1", | |
"dependencies": { | |
"express": "4.10.6", | |
"socket.io": "1.2.1" | |
}, | |
"private": true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web: node web.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = require('express')(); | |
var http = require('http').Server(app); | |
var io = require('socket.io')(http); | |
app.get('/', function (req, res) { | |
res.sendfile('index.html'); | |
}); | |
io.on('connection', function (socket) { | |
socket.on('image', function (data) { | |
console.log(data); | |
}); | |
}); | |
http.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment