-
Notifications
You must be signed in to change notification settings - Fork 0
/
capture.html
86 lines (75 loc) · 2.27 KB
/
capture.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="capture.css"/>
<style type="text/css">
</style>
</head>
<body>
<script src="http://10.0.1.220:1337/socket.io/socket.io.js"></script>
<script src="filters/sephia.js"></script>
<script src="filters/bw.js"></script>
<script src="filters/stretch.js"></script>
<script src="filters/vignette.js"></script>
<script src="gum.js"></script>
<div id="imageCaptureView"></div>
<script>
serviceUrl = 'http://10.0.1.220:1337';
var socket = io.connect(serviceUrl);
var imageCapturer = new ImageCapturer(
{
selector: '#imageCaptureView',
filter: sephia,
captureCallback: function(imageData) {
var body = document.querySelector('body');
var canvas = body.appendChild(document.createElement('canvas'));
canvas.setAttribute('height', imageData.height);
canvas.setAttribute('width', imageData.width);
var context = canvas.getContext('2d');
context.putImageData(imageData, 0, 0);
var url = canvas.toDataURL('jpg');
publishPicture(url);
body.removeChild(canvas);
}
});
imageCapturer.start();
var filters = [
sephia,
function (id) {
return sephia(vignette(id));
},
function (id) {
return stretch(bw(vignette(id)));
},
vignette,
bw,
function (id) {
return stretch(bw(id));
},
function (id) {
return id
}];
var idx = 0;
document.onkeydown = checkKey;
function checkKey(e) {
e = e || window.event;
if (e.keyCode == '37') {
idx--;
idx = idx % filters.length;
imageCapturer.filterMethod = filters[idx];
}
else if (e.keyCode == '39') {
idx++;
idx = idx % filters.length;
imageCapturer.filterMethod = filters[idx];
}
}
function publishPicture(data) {
socket.emit("addphoto", {
dataurl: data
})
console.log("Bilde publisert");
}
</script>
</body>
</html>