forked from MikeKovarik/exifr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
legacy.html
155 lines (133 loc) · 4.46 KB
/
legacy.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1"/>
<title>Exifr legacy bundle tester</title>
<link rel="stylesheet" type="text/css" href="../homepage/app.css">
<style>
h3, h4 {
margin-top: 16px;
margin-bottom: 4px;
}
#reload {
position: absolute;
right: 10px;
top: 10px;
}
a {
text-decoration: underline;
cursor: pointer;
}
</style>
</head>
<body>
<p>View this page in IE10 or IE11 to test compatibility of <code>full.legacy.umd.js</code> bundle</p>
<a id="reload" class="pointer">force reload</a>
<p>Exifr is built using the latest standards and web platform features. We use Babel to transpile the new syntax down to ES5 and Rollup to bundle all ESM files into single UMD bundle, compatible with older browsers.</p>
<h3>Polyfills</h3>
<p><strong>Since v4.1.0</strong> there are multiple shims baked into the <code>legacy</code> bundle. <strong>You are now required to only use <code>Promise</code> Polyfill.</strong></p>
<h3>Demos to try: (click on)</h3>
<ul>
<li id="demo1" class="pointer"><a>Parse TIFF (EXIF)</a></li>
<li id="demo2" class="pointer"><a>Extract depth map from XMP Extended</a></li>
<li id="demo3" class="pointer"><a>Parse ICC color profile</a></li>
</ul>
<h3>Output:</h3>
<pre id="output" style="font-size: 13px;"></pre>
<p>Or drag and drop your photo into this window.</p>
<script>
// important: dont use let - older browsers (samsung tizen tvs use arcane chromium)
var $output = document.querySelector('#output')
var $reload = document.querySelector('#reload')
window.onerror = function(message, source, lone, col, error) {
console.log('ONERROR')
var lines = [
'**************** ERROR ****************',
'message: ' + message,
'source: ' + source,
'lone: ' + lone,
'col: ' + col,
]
if (error) {
lines.push('description: ' + error.description)
lines.push('message: ' + error.message)
lines.push('name: ' + error.name)
lines.push('number: ' + error.number)
lines.push(error.stack)
}
printOutput(lines)
}
function printOutput(lines) {
$output.innerHTML += '\n' + lines.join('\n') + '\n\n'
}
// way to force-reload on phones where you can't do ctr+shift+r.
$reload.addEventListener('click', function() {window.location.reload(true)})
</script>
<!-- Promise polyfill -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/polyfill.min.js"></script>
<!-- exifr -->
<script src="../dist/full.legacy.umd.js"></script>
<script>
function printExif(output) {
$output.innerHTML += '\n' + JSON.stringify(output, null, 4)
}
function catchErrors(err) {
console.log('UNCAUGHT')
console.log(err)
printOutput([
'**************** UNCAUGHT ****************',
err.message,
err.stack,
])
}
// first demo
function parseFile(file, options) {
exifr.parse(file, options)
.then(printExif)
.catch(catchErrors)
}
// second demo
function extractDepthMap(file, options) {
var img = document.createElement('img')
exifr.parse(file, options)
.then(function(output) {
$output.innerHTML = ''
var mime = output.GDepth.Mime
var base64 = output.GDepth.Data
img.width = 400
img.src = 'data:' + mime + ';base64,' + base64
$output.appendChild(img)
})
.catch(catchErrors)
}
document.getElementById('demo1').addEventListener('click', runDemo1)
document.getElementById('demo2').addEventListener('click', runDemo2)
document.getElementById('demo3').addEventListener('click', runDemo3)
function runDemo1(clear) {
if (clear) $output.innerHTML = 'parsing file'
parseFile('../test/fixtures/IMG_20180725_163423-tiny.jpg')
}
function runDemo2(clear) {
if (clear) $output.innerHTML = 'extracting depth map'
extractDepthMap('../test/fixtures/xmp depth map.jpg', {xmp: true, mergeOutput: false, multiSegment: true})
}
function runDemo3(clear) {
if (clear) $output.innerHTML = 'parsing file'
parseFile('../test/fixtures/IMG_20180725_163423-tiny.jpg', {tiff: false, icc: true, multiSegment: true})
}
// load demo file first
runDemo1(false)
var dropzone = document.body
function prevent(e) {
e.preventDefault()
}
dropzone.addEventListener('dragenter', prevent)
dropzone.addEventListener('dragover', prevent)
dropzone.addEventListener('drop', function(e) {
e.preventDefault()
parseFile(e.dataTransfer.files[0])
})
</script>
</body>
</html>