This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.html
81 lines (64 loc) · 1.85 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BarcodeDetector Polyfill</title>
</head>
<body>
<p>
Upload one or multiple images depicting a barcode/qrcode.
If valid and supported, the decoded result should be displayed below.
</p>
<ul>
<li>
<a href="https://github.com/gruhn/barcode-detector/tree/master/example_codes">
example barcodes
</a>
</li>
<li>
<a href="https://github.com/gruhn/barcode-detector/tree/master/index.html">
demo source
</a>
</li>
</ul>
<input
id="fileInput"
type="file"
name="image"
accept="image/*"
capture="environment"
multiple
/>
<div id="output"></div>
</body>
<script type="text/javascript" src="https://unpkg.com/@zxing/library@latest"></script>
<script src="./dist/barcode-detector.umd.js"></script>
<script>
window.BarcodeDetector = BarcodeDetectorPolyfill
const fileInput = document.querySelector("#fileInput")
const output = document.querySelector("#output")
const barcodeDetector = new BarcodeDetector()
fileInput.onchange = async event => {
const files = [ ...event.target.files ];
output.innerHTML = "processing..."
const detectedCodesPerFile = await Promise.all(
files.map(async file => {
return [ file.name, await barcodeDetector.detect(file) ]
})
)
output.innerText = ""
detectedCodesPerFile.forEach(([ fileName, detectedCodes ]) => {
const title = document.createElement("h4")
title.innerText = fileName
output.appendChild(title)
const text = document.createTextNode(
JSON.stringify(detectedCodes, null, 2)
)
const pre = document.createElement("pre")
pre.appendChild(text)
output.appendChild(pre)
})
}
</script>
</html>