forked from gfwilliams/ThinGallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgallery.html
executable file
·522 lines (477 loc) · 23.3 KB
/
gallery.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
<meta charset="UTF-8">
<html>
<!--
ThinGallery
===========
https://github.com/gfwilliams/ThinGallery
Copyright 2016 Gordon Williams, [email protected] (Licensed as MPLv2)
A single-file gallery webpage. This uses EXIF thumbnails, XMLHttpRequest Range headers,
and your web server's own index pages to quickly display thumbnails for a directory without
having to fully load every image file, and without needing ANY server-side scripting.
Usage
-----
* Put `gallery.html` in the folder that contains your photos.
* Don't rename it to `index.html` as the web server's own index.html is required in order to list the photos
* Open gallery.html with a web browser, and enjoy
-->
<head>
<title>Gallery</title>
<meta name="viewport" content="minimal-ui, width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-title" content="Gallery">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="apple-touch-icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJgAAACYCAYAAAAYwiAhAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ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E+bWPIqMPXPmVM9bWKpz8zzIlVPUw428bKpnibBRjIb7RTso7/6fR/D7Y31tK/OqWC5xFI9bUi4KlBX7KJDLNXTElHTENkhmOpp6YfINamletqQWJNg20qmelpKwWpSa/ASx1bRVE9rz8FWpVVa2VRP22C1ClyRSsOZjXYK9unPHJ20I90ox2RZxsLCAlmWpfzFuFIFLkuJtBEvRT1tlIJ1ypQw6l6WYEOMYIPU08ZxrEMYzi9XgTelRPpOG7SeNuqo2y5ZQt6sAm8RluwsSI2UpY7+62njEqz9fQIc8FZ5LvIicEh6pJasv3raOGfLCY/zInHBIcAFCTYZJY4ZOtYLsLlc5zzwiLSQbKkFK+9weI4ZWDotJgYH/KFdsFXgrNpFJOJsdGrLPVp/o3YRidhwqbKysq98vwj8C9it9hEDUAc+TFyl0x7B1oCX1D5iQF6ibQlY523Mf4TW6Iv+yaND7CTYJeC02kn0yenoENvlYCVLwNvxpxDdsgrcScf6wmyHD35X7SV65Htss3h1p0fJvEAovgrRDeeA57f7i50Ec8BX0HJq0d3Q+CA7nAm62cOwrtzsi0JENx7kJotWb/W0tTPAo2pHsQOPRkd2ZGFx8bZb7eR14APAZ9Weoo2ngB/e6kPdCFYmcRlwWO0q4ozxyW4+2K1gAH8inKv8InqQ6TznXKeAZ7r9Qq+ivAjcr9nlXHI19v2LvXypn0h0FvgkqpPNE+eAT9HHmsF+h7rLwBeAx9HNU2aZNeCbsa/7un520Fzqx8DHCJV/1ctmK9d6Ifbts4PsKEWyvgo8DNwVD0YRbboj1rOxLx9OkWtvt5piUPYAXwaOAUeY4oc8zAm1mGOdAX5J4tt5DUOwTo4Q6mdHgbvVnxPBazFhPz/sydooBOtkP7AMHARWgL1xW+f6s6W4XdyaS9sMZ6tx+1XgPcKV1lfoWBA4bP4/AEdp7Bmo4zmPAAAAAElFTkSuQmCC">
<script type="text/javascript" charset="utf-8">
// Mobile Safari in standalone mode
if(("standalone" in window.navigator) && window.navigator.standalone){
// If you want to prevent remote links in standalone web apps opening Mobile Safari, change 'remotes' to true
var noddy, remotes = true;
document.addEventListener('click', function(event) {
noddy = event.target;
// Bubble up until we hit link or top HTML element. Warning: BODY element is not compulsory so better to stop on HTML
while(noddy.nodeName !== "A" && noddy.nodeName !== "HTML") {
noddy = noddy.parentNode;
}
if('href' in noddy && noddy.href.indexOf('http') !== -1 && (noddy.href.indexOf(document.location.host) !== -1 || remotes)) {
event.preventDefault();
document.location.href = noddy.href;
}
},false);
}
</script>
<style>
:root {
--thumb-width: 240px;
--thumb-height: 240px;
}
body {
color: white;
background-color: black;
}
a > .thumb { color: #fff; }
.thumb {
position: relative;
display: inline-block;
width:var(--thumb-width); height:var(--thumb-height);
margin: 4px;
cursor: pointer;
overflow: hidden;
}
.caption {
text-align: center;
font-size: 80%;
font-family: Helvetica, Arial, Sans-Serif;
text-shadow: 1px 0 0 #000, 0 -1px 0 #000, 0 1px 0 #000, -1px 0 0 #000;
position: absolute;
width:var(--thumb-width);
bottom:0px;
}
.thumbicon {
position: absolute;
font-size:48px;
left:50%;
top:50%;
transform: translateX(-50%) translateY(-50%);
}
.thumbimage {
position:absolute;top:0px;left:0px;
width:var(--thumb-width); height:var(--thumb-height);
background-position: center;
background-repeat: no-repeat;
background-size: contain;
}
.fullscreen {
position: absolute;
width: 100%;
min-height: 100%;
left: 0;
top: 0;
}
#modal {
background-color: rgba(0,0,0,0.8);
}
#bigimage {
position: absolute;
width: 100%;
min-height: 100%;
left: 0;
top: 0;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
}
#loadingimage {
position: absolute;
width: 100%;
min-height: 100%;
left: 0;
top: 0;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
}
#left,#right,#maximise {
position:absolute;
font-size:96px;
font-weight: bold;
}
#left,#right {
top: 50%; transform: translateY(-50%);
}
#left { left:10px; cursor:pointer; }
#right { right:10px; cursor:pointer; }
#maximise { right:10px;bottom:10px; cursor:pointer; }
#left,#right,#maximise {
text-shadow: 4px 0 0 #000, 0 -4px 0 #000, 0 4px 0 #000, -4px 0 0 #000, -3px -3px 0 #000, 3px -3px 0 #000, 3px 3px 0 #000, -3px -3px 0 #000;;
}
</style>
</head>
<body>
<div id="thumbs"></div>
<script>
var THUMB_SIZE = 240; // size when we have to load the full image and resize it
var MAX_CONCURRENT_REQ = 2;
var EXT_IMAGES = [".jpg",".jpeg",".png"];
var EXT_VIDEO = [".avi",".mov",".mpeg",".mpg",".mp4",".ogv"];
var EXT_AUDIO = [".mp3",".wav",".ogg"];
var EXT_TEXT = [".txt",".md"];
var requestsInProgress = 0;
var requestsQueued = [];
var baseURL = "";
var imageURLs = [];
var imageInfo = {};
var showingImage; // currently loading/showing image
var imageLoader, nextImageLoader, prevImageLoader;
// Get a thumbnail from EXIF data
function getThumbFromFullImage(url, callback) {
var img = document.createElement('img');
img.onload = function () {
var oc = document.createElement('canvas'),
octx = oc.getContext('2d');
if (img.width > img.height) {
oc.width = THUMB_SIZE;
oc.height = THUMB_SIZE * img.height / img.width;
} else {
oc.width = THUMB_SIZE * img.width / img.height;
oc.height = THUMB_SIZE;
}
octx.drawImage(img, 0, 0, oc.width, oc.height);
callback(oc.toDataURL());
};
img.src = url;
}
// Get a thumbnail from EXIF data
function getEXIFThumb(url, arraybuffer, callback) {
var arr = new Uint8Array(arraybuffer);
if (arr[0]!=0xFF || arr[1]!=0xD8) {
console.warn(url+" is not a valid JPEG");
return callback(url);
}
var offs = 2;
if (arr[offs]==0xFF && arr[offs+1]==0xE0) {
offs += arr[offs+3] + 2;
}
if (arr[offs]!=0xFF || arr[offs+1]!=0xE1) {
console.warn(url+" doesn't have EXIF tag at "+offs);
return callback(url);
}
var len = (arr[offs+2]<<8)|arr[offs+3];
if (len > arr.length) console.log("EXIF is "+len+" bytes long but we have only "+arr.length);
if (arr[offs+4]!=0x45 || arr[offs+5]!=0x78 || arr[offs+6]!=0x69 || arr[offs+7]!=0x66) {
console.warn(url+" doesn't have 'Exif' marker at "+offs);
return callback(url);
}
// Move on to TIFF header
offs += 10;
var rd16, rd32;
if (arr[offs]==0x49 && arr[offs+1]==0x49) {
// Intel align
rd16 = function(a) { return arr[a] | (arr[a+1]<<8); }
rd32 = function(a) { return arr[a] | (arr[a+1]<<8) | (arr[a+2]<<16) | (arr[a+3]<<24); }
} else if (arr[offs]==0x4D && arr[offs+1]==0x4D) {
// Motorola align
rd16 = function(a) { return arr[a+1] | (arr[a]<<8); }
rd32 = function(a) { return arr[a+3] | (arr[a+2]<<8) | (arr[a+1]<<16) | (arr[a]<<24); }
} else {
console.warn(url+" unknown byte alignment "+arr[offs]+","+arr[offs+1]);
return callback(url);
}
if (rd16(offs+2) != 0x002A) {
console.warn(url+" expecting TAG mark");
return callback(url);
}
// move on to IFD - Image file directory
offs+=rd32(offs+4);
// get tags
var tags = rd16(offs);
if (tags>100) {
console.warn(url+" too many EXIF tags!");
return callback(url);
}
offs += 2;
// iterate over tags
var thumbOrientation;
for (var i=0;i<tags;i++) {
var tag = rd16(offs+i*12);
//console.log(tag.toString(16));
if (tag==0x0112) { // JPEG orientation
thumbOrientation = rd32(offs+i*12+8);
}
}
// skip to next IFD
offs = rd32(offs + tags*12);
if (offs==0) {
console.warn(url+" no second IFD.");
return callback(url);
}
offs += 12;
var tags = rd16(offs);
if (tags>300) {
console.warn(url+" too many EXIF tags ("+tags+") in second IFD!");
return callback(url);
}
offs += 2;
// iterate over tags
var thumbOffset, thumbLen;
for (var i=0;i<tags;i++) {
var tag = rd16(offs+i*12);
//console.log(tag.toString(16));
if (tag==0x0201) thumbOffset = rd32(offs + i*12 + 8)+12; // ?
if (tag==0x0202) thumbLen = rd32(offs + i*12 + 8);
}
if (thumbOffset && thumbLen) {
//console.log("Thumb at",thumbOffset,"size",thumbLen,"tag",arr[thumbOffset].toString(16),arr[thumbOffset+1].toString(16));
var data = arr.subarray(thumbOffset, thumbOffset+thumbLen);
var blob = new Blob( [ data ], { type: "image/jpeg" } );
var urlCreator = window.URL || window.webkitURL;
var imageURL = urlCreator.createObjectURL( blob );
var rotation = 0;
if (thumbOrientation==6) rotation = 90;
callback(imageURL, rotation);
} else {
/* No thumbnail */
callback(url);
}
}
// Given a JPEG image, download the header and try and find a thumbnail
function getImageThumbnail(url, finishedCb, thumbCb) {
//console.log("Loading "+url);
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = "arraybuffer";
xhr.setRequestHeader('Range', 'bytes=0-60000');
xhr.onload = function (oEvent) {
getEXIFThumb(url, xhr.response, function(url, rotation) {
thumbCb(url, rotation);
finishedCb();
});
};
xhr.send(null);
}
// Load image thumbnails using a queue (don't don them all at once)
function getImageThumbnailThrottled(url, cb, passURL) {
if (requestsInProgress < MAX_CONCURRENT_REQ) {
requestsInProgress++;
function finishedCb() {
requestsInProgress--;
if (requestsQueued.length) {
var r = requestsQueued.shift();
getImageThumbnailThrottled(r.url, r.cb, r.passURL);
}
}
if (passURL) {
getThumbFromFullImage(url, function(url) {
cb(url);
finishedCb();
});
} else {
getImageThumbnail(url, finishedCb, cb);
}
} else {
//console.log("Delayed "+url);
requestsQueued.push({url:url,cb:cb,passURL:passURL});
}
}
// Make a displayable name from the URL
function getNiceName(href) {
var niceName = href;
// remove trailing slashes
while (niceName[niceName.length-1]=="/")
niceName = niceName.substr(0,niceName.length-1);
// if there's a slash mid-way, delete what was before
if (niceName.lastIndexOf("/")>=0)
niceName = niceName.substr(niceName.lastIndexOf("/")+1);
return niceName;
}
// Add a thumbnail with a 'wait' indicator that fills in when ready
function addDeferredThumb(thumbs, href) {
var niceName = getNiceName(href);
function thumbLoaded(url, rotate) {
imageInfo[href].thumb = url;
im.innerHTML =
'<div class="thumbimage" style="background-image:url('+url+');transform:rotate('+rotate+'deg)"></div>'+
'<div class="caption">'+decodeURIComponent(niceName)+'</div>';
}
var im = document.createElement("DIV");
im.innerHTML = '<div class="caption">'+decodeURIComponent(niceName)+'</div><div class="thumbicon">⌛</div>';
im.className = "thumb";
im.onclick = function(e) {
e.preventDefault();
console.log("Clicked "+href);
if (e.ctrlKey) {
window.open(href, '_blank');
} else {
document.getElementById("modal").setAttribute("style","display:block;top:"+window.scrollY+"px");
loadImage(href);
}
};
im = thumbs.appendChild(im);
getImageThumbnailThrottled(href, function(url,rotate) {
if (url == href) {
// We use getImageThumbnailThrottled so we can make sure
// that full images get loaded AFTER all the thumbnails
getImageThumbnailThrottled(url, thumbLoaded, true);
} else {
thumbLoaded(url, rotate);
}
});
}
// Add a simple thumbnail where a click opens a new window
function addBasicThumb(thumbs, href, iconText) {
var niceName = getNiceName(href);
var im = document.createElement("DIV");
im.innerHTML = '<div class="caption">'+decodeURIComponent(niceName)+'</div><div class="thumbicon">'+iconText+'</div>';
im.className = "thumb";
im.setAttribute("href", href);
im.onclick = function(e) {
e.preventDefault();
console.log("Clicked "+href);
window.open(href, '_blank');
};
im = thumbs.appendChild(im);
}
// Add thumbnail for a folder
function addFolder(thumbs, href) {
var niceName = getNiceName(href);
if (href.length < baseURL.length) niceName = "[BACK]";
var a = document.createElement("A");
a.href = window.location.pathname+"?"+href;
a.innerHTML = '<div class="thumb folder"><div class="caption">'+decodeURIComponent(niceName)+'</div><div class="thumbicon">📁</div></div>';
thumbs.appendChild(a);
}
// Scan the index page and add thumbnails for everything
function processIndexPage() {
//console.log(this.responseXML.title);
var thumbs = document.getElementById("thumbs");
var elements = this.responseXML.getElementsByTagName("a");
var handled = [];
for (var i=0;i<elements.length;i++) {
var href = elements[i].href;
var text = elements[i].innerText;
var parentText = elements[i].parentElement.innerText;
var re = new RegExp(text + '\/', "g");
if (handled.indexOf(href)>=0) continue;
if ((href[href.length-1]=="/" || parentText.match(re) )&& href!==baseURL) {
handled.push(href);
addFolder(thumbs, href);
}
}
for (var i=0;i<elements.length;i++) {
var href = elements[i].href;
var hrefl = href.toLowerCase();
var ext = hrefl.match(/\.[^\.]*$/);
if (!ext) continue;
ext=ext[0];
if (EXT_IMAGES.indexOf(ext)>=0) {
if (handled.indexOf(href)>=0) continue;
handled.push(href);
imageURLs.push(href);
imageInfo[href] = { thumb : "" };
addDeferredThumb(thumbs, href);
} else if (EXT_VIDEO.indexOf(ext)>=0) {
addBasicThumb(thumbs, href, "🎥");
} else if (EXT_AUDIO.indexOf(ext)>=0) {
addBasicThumb(thumbs, href, "🔊");
} else if (EXT_TEXT.indexOf(ext)>=0) {
addBasicThumb(thumbs, href, "🗎");
} else console.log("Unknown file type "+href+", ignoring.");
}
document.getElementById("left").setAttribute("style","visibility:inherit");
document.getElementById("right").setAttribute("style","visibility:inherit");
document.getElementById("maximise").setAttribute("style","visibility:inherit");
document.getElementById("modal").setAttribute("style","visibility:hidden");
}
// Load the index page from the web server and display thumbnails
function loadAllImages(url) {
var xhr = new XMLHttpRequest();
xhr.onload = processIndexPage;
baseURL = url;
xhr.open("GET", baseURL);
xhr.responseType = "document";
xhr.send();
}
// Load a full-size image and also try and load next/prev for faster navigation
function loadImage(url) {
document.getElementById("bigimage").setAttribute("style","background-image:url("+imageInfo[url].thumb+")");
imageLoader.onload = function() {
console.log("Full image loaded. Loading next and prev.");
var i = imageURLs.indexOf(showingImage);
if (i>=0) {
if (i>0) prevImageLoader.src = imageURLs[i-1]+"?rand";
if (i<imageURLs.length-1) nextImageLoader.src = imageURLs[i+1]+"?rand";
}
};
imageLoader.src = url+"?rand";
document.getElementById("loadingimage").setAttribute("style","background-image:url("+url.replace(/\(/g, "\\(").replace(/\)/g, "\\)")+"?rand)");
showingImage = url;
}
function onModalClicked(e) {
e.preventDefault();
if (e.target.id=="left" || e.target.id=="right" || e.target.id=="maximise") return;
document.getElementById("modal").setAttribute("style","visibility:hidden");
document.getElementById("bigimage").setAttribute("style","");
document.getElementById("loadingimage").setAttribute("style","");
showingImage = null;
}
function onChangeModal(e, dir) {
e.preventDefault();
var i = imageURLs.indexOf(showingImage);
if (i<0) i=0;
i += dir;
if (i<0) i+= imageURLs.length;
if (i>=imageURLs.length) i-= imageURLs.length;
loadImage(imageURLs[i]);
}
function onMaximiseClicked(e) {
e.preventDefault();
if (!showingImage) return;
window.open(showingImage, '_blank').focus();
}
window.onscroll = onModalClicked;
window.onload = function() {
imageLoader = document.createElement("IMG");
nextImageLoader = document.createElement("IMG");
prevImageLoader = document.createElement("IMG");
document.getElementById("modal").onclick = onModalClicked;
document.getElementById("left").onclick = function(e) { onChangeModal(e,-1); };
document.getElementById("right").onclick = function(e) { onChangeModal(e,+1); };
document.getElementById("maximise").onclick = onMaximiseClicked;
document.addEventListener("keydown", function (e) {
if (e.keyCode==37) onChangeModal(e,-1);
if (e.keyCode==39) onChangeModal(e,1);
});
if (window.location.search.length>1)
loadAllImages(window.location.search.substr(1));
else
loadAllImages(".");
};
</script>
<div id="modal" class="fullscreen">
<div id="bigimage" style="visibility:hidden"></div>
<div id="loadingimage" style="visibility:hidden"></div>
<div id="left" style="visibility:hidden">◀</div>
<div id="right" style="visibility:hidden">▶</div>
<div id="maximise" style="visibility:hidden">➘</div>
</div>
</div>
</body>
</html>