-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
139 lines (113 loc) · 3.64 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Read Thumbnail from EXIF</title>
<style>
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
display: inline-block;
text-align: center;
width: 100%;
}
form {
height: 80px;
display: flex;
justify-content: center;
align-items: center;
background-color: #f1f1f1;
margin-bottom: 20px;
flex-direction: column;
}
img {
vertical-align: middle;
margin: 5px;
border-radius: 6px;
box-shadow: 0px 0px 5px #cccccc;
position: relative;
font-family: 'system-ui';
overflow: hidden;
}
img:before {
content: "\01F494" "\00000a" attr(title);
font-size: 16px;
font-family: "system-ui";
color: #606060;
color: #00000080;
display: flex;
position: absolute;
z-index: 2;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #eee;
justify-content: center;
align-items: center;
white-space: pre;
}
</style>
</head>
<body>
<form>
<div>Select JPG images to extract thumbnails</div>
<input type="file" multiple>
</form>
<section id="container"></section>
<template id="imageTemplate">
<img src="${src}" width="${width}" height="${height}" title="${title}">
</template>
<script type="module">
import getExifThumb from './getExifThumb.js';
document.querySelector('input').addEventListener('change', async (e)=>{
e.stopPropagation();
e.preventDefault();
const target = e.target || e.dataTransfer ;
const files = target && target.files;
console.time('Total Time ------->');
const container = document.getElementById("container");
const template = document.getElementById("imageTemplate").innerHTML;
container.innerText = '';
let templateContent = '';
let maxStartIndex = 0, maxEndIndex = 0;
// for (let index = 0; index < 100; ++index) { // Performance test
for(const file of files){
let response = await getExifThumb(file);
if (response.ok == false) {
console.warn(response.statusText, response);
continue;
}
maxStartIndex = Math.max(response.start, maxStartIndex);
maxEndIndex = Math.max(response.end, maxEndIndex);
let title = response.width + 'x' + response.height + 'px' + '\n\n' + response.fileName;
let variaveis = {
fileName: response.fileName,
title: title,
src: response.src,
width: response.width,
height: response.height,
}
if (response.thumbFound == false) {
console.warn(response.statusText, response);
let title = response.statusText + '\n\n' + response.fileName;
variaveis = {...variaveis, title: title, width: 256, height: 171 }
}
// templateContent += templateApply(template, variaveis);
templateContent = templateApply(template, variaveis);
container.insertAdjacentHTML( 'beforeend', templateContent );
} //endFor
// } // endFor Performance test
// container.insertAdjacentHTML( 'beforeend', templateContent );
console.log('maxStartIndex', maxStartIndex, 'maxEndIndex', maxEndIndex);
console.timeEnd('Total Time ------->');
});
const templateApply = (tpl, args) => tpl.replace(/\${(\w+)}/g, (_, v) => { return args[v] || '' });
</script>
</body>
</html>