-
Notifications
You must be signed in to change notification settings - Fork 3
/
duplicate-image-finder.html
719 lines (580 loc) · 16 KB
/
duplicate-image-finder.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
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
<!-- Copyright: Vitali Fedulov ([email protected]) 2015-2023 -->
<!DOCTYPE html>
<html lang="en">
<head>
<title>Duplicate image finder</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto">
<link rel="icon" type="image/png" href="images/favicon.png">
<link rel="stylesheet" type="text/css" href="css/clustering.css">
</head>
<body>
<div class="flex-container-select-files">
<div class="flex-center-horizontally">
<div>
<h1 class="text-centered clustering-title">Duplicate Image Finder</h1>
</div>
<div id="terms-of-service">
<p class="terms-of-service-header text-centered">Terms of service and data protection</p>
<div id="terms"></div>
</div>
<div>
<p id="messages" class="hidden">Messages</p>
<div id="ok-button" class="text-centered">
<div class="button">OK</div>
</div>
<div id="file-selector" class="text-centered">
<input class="hidden" type="file" id="filesSelected" webkitdirectory multiple accept="image/*" onchange="v43(this.files)" onclick="v12()">
<a class="button">Select a folder with images</a>
</div>
<div class="fast-option">
<input type="checkbox" id="fast-option" onclick="v11()">
<div class="option-text">Option to accelerate the search (recommended). It has somewhat larger chance to mismatch pictures. The acceleration can be considerable for folders with many JPEG images.</div>
</div>
<div class="link-block text-centered">
<a class="home-cancel-link" id="cancel-link" onclick="v42()">Cancel</a>
<a class="home-cancel-link" href="/similar.pictures/index.html">Home</a>
</div>
</div>
</div>
</div>
<div class="fixed-top hidden">
<div class="fixed-top-gray">
<a href = "index.html" class="logo-href"><span class="logo">Duplicate Image Finder</a>
<div class="button button-new-search">New clustering</div>
</div>
<div class="fixed-white-1">
<div class="progress">
<div id="progress-bar"></div>
</div>
<div class="progress-text"></div>
</div>
<div class="fixed-white-2 hidden">
<span class="found-clusters"></span> <span> (</span><span class="view-list">show/hide as list</span><span>)</span>
<textarea class="textarea"></textarea>
<p class="explanation">
<small class="small">Scroll down to view all clusters. Keep the browser tab open to avoid stopping the clustering process.</small>
</p>
</div>
</div>
<div id="clusters" class="clusters"></div>
<script>
function load(url, element) {
fetch(url)
.then(response => response.text())
.then(data => {
element.innerHTML = data;
})
.catch(error => {
console.error('Error:', error);
});
}
window.addEventListener('DOMContentLoaded', () => {
v5();
load("tos_en.html", document.querySelector("#terms"));
document.querySelector("#ok-button").style.display = 'none';
document.querySelector("#cancel-link").style.display = 'none';
document.querySelector(".button-new-search").addEventListener('click', (e) => {
v61();
});
document.querySelector("#ok-button").addEventListener('click', (e) => {
v61();
});
window.scrollTo({top: 0});
});
var v80 = {
v94 : 24, v75 : 2,
v36 : 12,
v46 : 80000, v7 : 40*1024*1024, v72 : 0, v60 : 0,
v13 : false,
v91 : 0, v73 : 0,
v102 : [],
v49 : [], v8 : [],
v77 : [], v76 : [],
v79 : [],
v45 : 0,
v20 : [],
v122 : 10, v116 : 100, v32 : 50, v65 : 0.2, v55 : 2, v74 : 0.7,
v35 : [], v27 : /(^image\/gif$)|(^image\/jpeg$)|(^image\/jpg$)|(^image\/bmp$)|(^image\/png$)|(^image\/webp$)/,
v81 : "",
v100 : null,
v52 : 0,
v28 : false,
v1 : 1000,
v0 : null,
v15 : "image/jpeg", v10 : 0.6,
v39 : 160, v34 : '\n',
v19 : '\n\n',
v21 : 0,
v17 : false,
v6 : 0,
};
var v78 = {
v33 : v80.v36 * v80.v36,
v119 : v80.v94 * v80.v36, v89 : v80.v94 * v80.v94,
};
function v11() {
localStorage.setItem("fast-option", document.querySelector("#fast-option").checked);
return;
}
function v5() {
if (localStorage.getItem("fast-option") == null) {
document.querySelector("#fast-option").checked = true;
return;
}
if (localStorage.getItem("fast-option") == 'false') {
document.querySelector("#fast-option").checked = false;
} else {
document.querySelector("#fast-option").checked = true;
}
return;
}
function v42() {
v61();
}
function v61() {
location.reload();
window.scrollTo({top: 0});
}
document.getElementById('file-selector').addEventListener('click', v26);
function v26() {
var v106 = document.getElementById('filesSelected');
if (!!v106.webkitdirectory == false) {
alert('This browser does not support folder selection. Please try latest desktop Chrome, Firefox or Edge.');
return;
}
v106.click();
}
function v37(v98, v108, v117, v82) {
v98.readAsArrayBuffer(v117.slice(0, v80.v46));
v98.onload = function (v107) {
var v105 = new Uint8Array(v107.target.result),
v109, v128;
var v125 = v105.length;
var v147 = 0;
for (v147 = 2; v147 < v125; v147++) {
if (v105[v147] == 0xFF) {
if (!v109) {
if (v105[v147 + 1] == 0xD8) {
v109 = v147;
}
} else {
if (v105[v147 + 1] == 0xD9) {
v128 = v147 + 2; break;
}
}
}
}
if (v109 && v128) {
v82(new Blob([v105.subarray(v109, v128)], {type:"image/jpeg"}));
} else {
v82(null);
}
};
v98.onerror = function() {
v82(null);
};
}
function v22(v92) {
if (v80.v21 < 2) {
document.querySelector(".fixed-top").style.display = 'none';
document.querySelector(".flex-container-select-files").style.display = 'block';
document.querySelector("#messages").textContent = "The selected folder has less than 2 images of supported types. There is nothing to compare. Please select a different folder.";
document.querySelector("#messages").style.display = 'block';
document.querySelector("#file-selector").style.display = 'none';
document.querySelector("#cancel-link").style.display = 'none';
document.querySelector("#ok-button").style.display = 'block';
return;
}
document.querySelector(".progress").parentNode.removeChild( document.querySelector(".progress"));
var v151 = "s";
if (v92 + 1 == 1) {
v151 = "";
}
v14(".progress-text", "Successfully scanned ".concat(v80.v100.length, " file", v151, "."));
if (v80.v45 == 0) {
v14(".progress-text", "Zero similar images found from the successfully scanned ".concat(v80.v100.length, " file", v151, "."));
}
return;
}
function v70() {
var v68 = 0;
var v140 = 0, v138 = 0, v137 = 0, v137 = 0;
for (v140 = 1; v140 < v80.v94 - 1; v140+= v80.v75) {
for (v138 = 1; v138 < v80.v94 - 1; v138+= v80.v75) {
var v16 = [];
for (v137 = -1; v137 < 2; v137++) {
for (v130 = -1; v130 < 2; v130++) {
v16.push((v138 + v130) * v80.v94 + v140 + v137);
}}
v80.v102[v68] = v16;
v68++;
}}
v80.v88 = v16.length;
v80.v91 = v68;
v80.v73 = 1 / v68;
v78.v67 = v80.v91 * v80.v32 * v80.v32 * v80.v65;
v78.v57 = v78.v67 * v80.v55;
return;
}
v70();
function v4(v108, v71) {
var v95 = [];
var v58 = v80.v20[v108];
var v51 = v80.v20[v71];
if (typeof v58 === "undefined" && typeof v51 === "undefined") {
v80.v20[v108] = v80.v45;
v80.v20[v71] = v80.v45;
v80.v79.push([v108, v71]);
v80.v45++;
v9(v80.v45 - 1);
v18(v80.v45 - 1, v108);
v18(v80.v45 - 1, v71);
return;
}
if (typeof v58 === "number" && typeof v51 === "undefined") {
v95 = v80.v79[v58];
v95.push(v71);
v80.v20[v71] = v58;
v80.v79[v58] = v95;
v18(v58, v71);
return;
}
if (typeof v58 === "undefined" && typeof v51 === "number") {
v95 = v80.v79[v51];
v95.push(v108);
v80.v20[v108] = v51;
v80.v79[v51] = v95;
v18(v51, v108);
return;
}
}
function v64(v71) {
var v136 = 0, v133 = 0;
var v132 = 0, v134 = 0, v131 = 0, v135 = 0;
var v111 = 0, v83 = 0, v108 = 0;
var v40 = [[], [], []];
var v38 = v80.v49[v71];
v80.v8[v71] = v38;
var v108 = 0;
for (v108 = v71 - 1; v108 >= 0; v108--) {
v132 = v80.v77[v108], v134 = v80.v76[v108];
v131 = v80.v77[v71], v135 = v80.v76[v71];
if (v132 * v135 * v80.v116 + v80.v122 * v132 * v131 < v131 * v134* v80.v116 ||
v132 * v135 * v80.v116 > v131 * v134 * v80.v116 + v80.v122 * v132 * v131) {
continue;
}
v40 = v80.v8[v108];
v111 = 0;
for (v83 = 0; v83 < v80.v91; v83++) {
v136 = v40[0][v83];
v133 = v38[0][v83];
v111 += (v136 - v133) * (v136 - v133);
}
if (v111 > v78.v67) {
continue;
}
v111 = 0;
for (v83 = 0; v83 < v80.v91; v83++) {
v136 = v40[1][v83];
v133 = v38[1][v83];
v111 += (v136 - v133) * (v136 - v133);
}
if (v111 > v78.v57) {
continue;
}
v111 = 0;
for (v83 = 0; v83 < v80.v91; v83++) {
v136 = v40[2][v83];
v133 = v38[2][v83];
v111 += (v136 - v133) * (v136 - v133);
}
if (v111 > v78.v57) {
continue;
}
v4(v108, v71);
v3();
}
return;
}
function v14(v24, v115) {
document.querySelector(v24).textContent = v115;
}
function v3() {
var v151 = "s";
if (v80.v45 == 1) {
v151 = "";
}
v14(".found-clusters", "Found ".concat(v80.v45, ' cluster', v151));
}
var v47 = document.querySelector("#progress-bar");
function v2(v92) {
if (v92 + 1 == v80.v52) {
return;
}
v14(".progress-text", "Please wait... Reading ".concat(v92, ' from ', v80.v52, ' selected files.'));
var v90 = ~~(100 * (v92 + 1) / v80.v52);
if (v90 < 5) {
v90 = 5;
}
v47.style.width = "".concat(v90, "%");
}
function v86(v50, v30) {
var v112 = document.createElement("div");
v112.className = v50;
v30.appendChild(v112);
return v112;
}
var v48 = document.getElementById("clusters");
function v9(v69) {
var v53 = v86("cluster", v48);
var v66 = v86("cluster-num", v53);
v66.textContent = v69 + 1;
var v25 = v86("cluster-content", v53);
v86("cluster-imgs", v25);
v86("cluster-paths", v25);
}
function v18(v69, v108) {
var v85 = document.querySelectorAll( ".cluster-imgs" )[v69];
var v97 = v86("cluster-img-div", v85);
var v127 = new Image();
v127.classList.add("cluster-img");
v97.appendChild(v127);
var v54 = v86("image-size", v97);
var v23 = document.querySelectorAll( ".cluster-paths" )[v69];
var v56 = v86("img-path", v23);
var v117 = v80.v100[v80.v35[v108]];
v56.textContent = v117.webkitRelativePath;
v29(v117, v127, v54);
}
function v29(v117, v127, v54) {
var v98 = new FileReader(); v98.v117 = v117;
v98.onload = function() {
return function(e) {
var v44 = new Image();
v44.src = e.target.result;
var v93 = document.createElement("canvas");
var v126 = v93.getContext("2d", { willReadFrequently: true });
v44.onload = function() {
v54.textContent = "".concat(v44.width, "×", v44.height);
if (v44.width >= v44.height) {
v93.height = v80.v39 * 2; v93.width = ~~(v44.width * v93.height / v44.height);
} else {
v93.width = v80.v39 * 2;
v93.height = ~~(v44.height * v93.width / v44.width);
}
v127.width = v93.width / 2; v127.height = v93.height / 2;
v126.drawImage(v44, 0, 0, v93.width, v93.height);
v127.src = v93.toDataURL(v80.v15, v80.v10);
v93 = null; v126 = null;
v44 = null;
v98 = null;
v80.v6++;
};
};
} ();
v98.readAsDataURL(v117);
}
function v62() {
var v110 = "";
var v150 = 0;
var v147 = 0;
for (v150 = 0; v150 < v80.v45; v150++) {
var v59 = v80.v79[v150];
for (v147 = 0; v147 < v59.length - 1; v147++) {
v110 = v110.concat(v80.v100[v80.v35[v59[v147]]].webkitRelativePath, v80.v34);
}
v110 = v110.concat(v80.v100[v80.v35[v59[v147]]].webkitRelativePath, v80.v19);
}
v110 = v110.slice(0, -2);
document.querySelector(".textarea").value = v110;
document.querySelector(".textarea").classList.toggle("textareaon");
}
function v12() {
document.querySelector("#terms-of-service").style.display = 'none';
v80.v0 = setTimeout(function() {
document.querySelector("#messages").textContent = 'Please wait if you selected a very large number of images: it may take tens of seconds before the clustering starts.';
document.querySelector("#messages").style.display = 'block';
document.querySelector("#file-selector").style.display = 'none';
document.querySelector(".fast-option").style.display = 'none';
document.querySelector("#cancel-link").style.display = 'block';
}, v80.v1);
}
function v118(v87, v147, v139, v120) {
return [v87[v139 * (v120 * 4) + (v147 * 4)],
v87[v139 * (v120 * 4) + (v147 * 4) + 1],
v87[v139 * (v120 * 4) + (v147 * 4) + 2]];
}
function v41(v87) {
var v101 = [[], [], []];
var v147 = 0, v139 = 0, v142 = 0, v141 = 0;
var v145 = 0, v143 = 0, v144 = 0;
var v104 = 0, v99 = 0, v103 = 0; var v151 = 0;
var v84 = [];
var v129 = 0, v148 = 0, v146 = 0;
for (v129 = 0; v129 < v80.v91; v129++) {
v104 = 0, v99 = 0, v103 = 0;
v151 = 0;
for (v148 = 0; v148 < v80.v88; v148++ ) {
v147 = ~~(v80.v102[v129][v148] / v80.v94);
v139 = v80.v102[v129][v148] % v80.v94;
for (v146 = 0; v146 < v78.v33; v146++) {
v142 = ~~(v146 / v80.v36);
v141 = v146 % v80.v36;
v84 = v118(v87, v147 * v80.v36 + v142,
v139 * v80.v36 + v141, v78.v119);
v145 = v84[0];
v143 = v84[1];
v144 = v84[2];
v104 += 0.299000 * v145 + 0.587000 * v143 + 0.114000 * v144;
v99 += 128 - 0.168736 * v145 - 0.331264 * v143 + 0.500000 * v144;
v103 += 128 + 0.500000 * v145 - 0.418688 * v143 - 0.081312 * v144;
v151++;
}
}
v101[0][v129] = v104 / v151; v101[1][v129] = v99 / v151;
v101[2][v129] = v103 / v151;
}
return [v63(v101[0]), v63(v101[1]), v63(v101[2])];
}
function v63(v124) {
var v96 = [];
var v149 = v124.length;
var v121 = 0; var v113 = Number.POSITIVE_INFINITY;
var v141 = 0;
for (v141 = 0; v141 < v149; v141++) {
if (v124[v141] > v121) {
v121 = v124[v141];
} else if (v124[v141] < v113) {
v113 = v124[v141];
}
}
var v123 = v121 - v113;
for (v141 = 0; v141 < v149; v141++) {
v96[v141] = (v124[v141] - v113) * 255 / v123;
}
return v96;
}
function v43(v100) {
v80.v13 = document.querySelector("#fast-option").checked;
v80.v6 = 0;
clearTimeout(v80.v0);
document.querySelector("#file-selector").style.display = 'none';
v80.v100 = v100;
v80.v81 = v100[0].webkitRelativePath.split("/")[0];
v80.v52 = v100.length;
var v92 = 0; var v108 = 0;
var v98 = new FileReader();
var v127 = new Image();
var v93 = document.createElement("canvas");
v93.width = v78.v119;
v93.height = v78.v119;
var v126 = v93.getContext("2d", { willReadFrequently: true });
document.querySelector(".flex-container-select-files").style.display = 'none';
document.querySelector(".fixed-top").style.display = 'block';
document.querySelector(".view-list").addEventListener('click', (e) => {
v62();
});
document.querySelector(".fixed-white-2").style.display = 'block';
v3();
v31(v92, v108, v98, v127, v126);
}
function v31(v92, v108, v98, v127, v126) {
if (v92 >= v80.v52) {
v22(v92);
return;
}
if (!v80.v27.test(v80.v100[v92].type) || v80.v100[v92].size > v80.v7) {
v92++;
v31(v92, v108, v98, v127, v126);
return;
}
if (v80.v13 &&
v80.v100[v92].type == "image/jpeg" &&
!v80.v28) {
v37(v98, v108, v80.v100[v92], function(v114) {
if (v114 == null) {
v80.v28 = true;
v31(v92, v108, v98, v127, v126);
return;
} else {
v127.src = URL.createObjectURL(v114);
v127.onload = function() {
v80.v21++;
if (v92 < 5 || v92 % 5 === 0) {
v2(v92);
}
v126.drawImage(v127, 0, 0, v78.v119, v78.v119);
v80.v49[v108] = v41(v126.getImageData(0, 0, v78.v119, v78.v119).data);
v80.v77[v108] = v127.width;
v80.v76[v108] = v127.height;
v80.v35[v108] = v92;
v80.v72 = v108 + 1;
v80.v60 = v92 + 1;
URL.revokeObjectURL(v127.src);
v64(v108);
v92++;
v108++;
if (!v80.v17) {
v80.v17 = true;
}
v80.v28 = false;
v31(v92, v108, v98, v127, v126);
return;
};
v127.onerror = function() {
URL.revokeObjectURL(v127.src); v80.v28 = true;
v31(v92, v108, v98, v127, v126);
return;
};
return;
}
});
} else {
v80.v28 = true;
}
if (v80.v28 == false) {
return;
}
v98.readAsDataURL(v80.v100[v92]);
v98.onerror = function() {
v92++;
v80.v28 = false;
v31(v92, v108, v98, v127, v126);
return;
};
v98.onload = function(evt) {
v127.src = evt.target.result;
v127.onerror = function() {
v92++;
v80.v28 = false;
v31(v92, v108, v98, v127, v126);
return;
};
v127.onload = function() {
v80.v21++;
if (v92 < 5 || v92 % 5 === 0) {
v2(v92);
}
v126.drawImage(v127, 0, 0, v78.v119, v78.v119); v80.v49[v108] = v41(v126.getImageData(0, 0, v78.v119, v78.v119).data);
v80.v77[v108] = v127.width;
v80.v76[v108] = v127.height;
v80.v35[v108] = v92;
v80.v72 = v108 + 1;
v80.v60 = v92 + 1;
v64(v108);
v92++;
v108++;
if (!v80.v17) {
v80.v17 = true;
}
v80.v28 = false;
v31(v92, v108, v98, v127, v126);
return;
};
};
}
</script>
</body>
</html>