-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbundle.js
90 lines (76 loc) · 1.94 KB
/
bundle.js
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
87
88
89
90
navigator.getMedia = ( navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
navigator.getMedia (
// constraints
{
video: true,
audio: false
},
// successCallback
function(localMediaStream) {
var video = document.querySelector('video');
var canvas = document.querySelector('#in');
var context = canvas.getContext('2d');
video.src = window.URL.createObjectURL(localMediaStream);
setInterval(function() {
canvas.width = video.videoWidth/2;
canvas.height = video.videoHeight/2
context.drawImage(video, 0,0, canvas.width, canvas.height);
video.play();
}, 1000/24);
},
// errorCallback
function(err) {
console.log("The following error occured: " + err);
}
);
$(function() {
var gif = new GIF({
workers: 4,
workerScript: '/lib/gif.worker.js',
width: 320,
height: 240
});
$('button#reset', function() {
var gif = new GIF({
workers: 4,
workerScript: '/lib/gif.worker.js',
width: 320,
height: 240
});
});
var canvas = $('canvas')[0];
var capture = function() {
console.log('captured');
gif.addFrame(canvas, { copy: true });
};
gif.on('start', function() {
console.log('starting');
});
gif.on('progress', function(p) {
console.log(p);
});
gif.on('finished', function(blob) {
img = $('img');
img.attr('src', URL.createObjectURL(blob));
});
$('button#1sec').click(function() {
var start = function() {
var interval = setInterval(capture, 250);
setTimeout(function() {
clearInterval(interval);
console.log('cleared');
gif.running = false;
gif.render();
}, 2500);
};
start();
});
$('button#take').click(function() {
capture();
gif.running = false;
gif.render();
});
});