-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.html
185 lines (158 loc) · 5.67 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<html>
<head>
<meta charset="utf-8"/>
<script type="text/javascript" src="metadata.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" src="https://maps.googleapis.com/maps/api/js?sensor=true"></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() {
//get the APP markers
var markers = metadata.parse(reader.result);
console.log(markers);
var size = getImageSize(img, 1024, 1024);
//get exif if it exists
var startTime = Date.now();
var exif = metadata.getExif(reader.result, markers);
var exifDuration = (Date.now() - startTime);
ctx.canvas.height = size.height;
ctx.canvas.width = size.width;
if (exif.hasExif) {
switch(exif.orientation)
{
case 3:
ctx.rotate(Math.PI);
ctx.translate(-size.width, -size.height);
break;
case 6:
ctx.canvas.height = size.width;
ctx.canvas.width = size.height;
ctx.rotate(Math.PI / 2);
ctx.translate(0, -size.height);
break;
case 8:
ctx.canvas.height = size.width;
ctx.canvas.width = size.height;
ctx.rotate(Math.PI * 3/2);
ctx.translate(-size.width, 0);
break;
}
}
ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, size.width, size.height);
var dataURL = ctx.canvas.toDataURL('image/jpeg', 0.96);
var ab = dataURItoArrayBuffer(dataURL);
startTime = Date.now();
var newImageBlob = metadata.copy(reader.result, ab, markers);
var copyDuration = (Date.now() - startTime);
var template = $('#template').clone();
var img2 = new Image()
img2.src = window.URL.createObjectURL(newImageBlob);
template.find("#img").append(img2);
template.attr('id', 'md_' + index);
var info = template.find('#info');
info.children('#pt').html(copyDuration + "ms");
info.children('#et').html(exifDuration + "ms");
info.children('#fs').html(newImageBlob.size + " bytes");
if (exif.hasExif) {
var ex = info.find('#exif');
ex.children('#ma').html(exif.make);
ex.children('#mo').html(exif.model);
ex.children('#ar').html(exif.artist);
ex.children('#cr').html(exif.copyright);
ex.children('#or').html(exif.orientation);
ex.show();
if (exif.hasGPSLocation) {
var gps = ex.find('#gps');
gps.children('#lat').html(exif.latitude);
gps.children('#long').html(exif.longitude);
gps.show();
var mapOptions = {
center: new google.maps.LatLng(exif.latitude, exif.longitude),
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(gps.children('#map')[0], mapOptions);
}
}
index++;
$('#tbl').append(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>metadata.js Example</h1>
<input type="file" id="input"/>
<br>
<div style="display:none">
<table id="template" name="template" border="0" cellpadding="0" cellspacing="0" style="bottom-margin:10px;">
<tr>
<td id="img" style="float:left;"></td>
<td id="info" style="vertical-align:top;padding-left:10px;">
<b>Copy Duration:</b> <span id="pt"></span><br>
<b>Exif Duration:</b> <span id="et"></span><br>
<b>File Size:</b> <span id="fs"></span><br>
<div id="exif" style="display:none">
<b>Make:</b> <span id="ma"></span><br>
<b>Model:</b> <span id="mo"></span><br>
<b>Artist:</b> <span id="ar"></span><br>
<b>Copyright:</b> <span id="cr"></span><br>
<b>Orientation:</b> <span id="or"></span><br>
<div id="gps" style="display:none">
<b>Latitude:</b> <span id="lat"></span><br>
<b>Longitude:</b> <span id="long"></span><br>
<div id="map" style="width:300px;height:212px"></div>
</div>
</div>
</td>
</tr>
</table>
</div>
<div id="tbl"></div>
<canvas id="canvas" style="display:none;"></canvas>
</body>
</html>