-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathexample.html
97 lines (80 loc) · 3.02 KB
/
example.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
87
88
89
90
91
92
93
94
95
96
97
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="gify.js"></script>
<script type="text/javascript" src="jdataview.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
var index = 1;
function handleFiles(e) {
var file = e.target.files[0];
var ctx = document.getElementById('canvas').getContext('2d');
var reader = new FileReader();
reader.onload = function (event) {
var blob = new Blob([event.target.result]);
window.URL = window.URL || window.webkitURL;
var blobURL = window.URL.createObjectURL(blob);
var img = new Image();
img.src = blobURL;
img.onload = function () {
var startTime = Date.now();
var gifInfo = gify.getInfo(reader.result);
var template = $('#template').clone();
template.attr('id', 'gify_' + index);
template.html('<b>File:</b> ' + file.name + '<br>');
template.append('<b>Duration:</b> ' + (Date.now() - startTime) + ' ms.<br>');
template.append('<b>Frames:</b> ' + gifInfo.images.length + '<br>');
template.append('<pre id="json">' + JSON.stringify(gifInfo, undefined, 2) + '</pre><br>');
index++;
$('#tbl').prepend(template);
};
};
reader.readAsArrayBuffer(file);
}
function getImageSize(img, maxWidth, maxHeight) {
var ratio = 1;
if (img.width > maxWidth) {
ratio = maxWidth / img.width;
} else if (img.height > maxHeight) {
ratio = maxHeight / img.height;
}
var size = {};
size.height = Math.round(img.height * ratio);
size.width = Math.round(img.width * ratio);
return size;
}
function dataURItoArrayBuffer(dataURI) {
var byteString;
if (dataURI.split(',')[0].indexOf('base64') >= 0) {
byteString = atob(dataURI.split(',')[1]);
} else {
byteString = unescape(dataURI.split(',')[1]);
}
// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
// write the bytes of the string to an ArrayBuffer
var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return ab;
}
window.onload = function () {
var input = document.getElementById('input');
input.addEventListener('change', handleFiles);
};
</script>
</head>
<body style="font-family: Arial, Helvetica, sans-serif">
<h1>gify Example</h1>
<input type="file" id="input" />
<br />
<div style="display: none">
<div id="template" style="margin-bottom: 10px"></div>
</div>
<br />
<div id="tbl"></div>
<canvas id="canvas" style="display: none"></canvas>
</body>
</html>