-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
81 lines (61 loc) · 3.01 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">
<meta name="author" content="ZXing for JS">
<title>ZXing TypeScript | Decoding QR Code from image file</title>
<link rel="preload" as="style" onload="this.rel='stylesheet';this.onload=null" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
<link rel="preload" as="style" onload="this.rel='stylesheet';this.onload=null" href="https://unpkg.com/[email protected]/normalize.css">
<link rel="preload" as="style" onload="this.rel='stylesheet';this.onload=null" href="https://unpkg.com/[email protected]/dist/milligram.min.css">
</head>
<body>
<main class="wrapper" style="padding-top:2em">
<section class="container" id="demo-content">
<h1 class="title">Scan QR Code from Image</h1>
<p>
<a class="button-small button-outline" href="../../index.html">HOME 🏡</a>
</p>
<p>
This example shows how to scan a QR code with ZXing javascript library from an image.
The example decodes from the
<code>src</code> in
<code>img</code> tag, however is also possible to decode directly from an url without an
<code>img</code> tag.
</p>
<div>
<a class="button" id="decodeButton">Decode</a>
</div>
<div>
<img id="img" src="IMG_0775.JPG" style="border: 1px solid gray"></img>
</div>
<label>Result:</label>
<pre><code id="result"></code></pre>
<p>See the <a href="https://github.com/zxing-js/library/tree/master/docs/examples/qr-image/">source code</a> for this example.</p>
</section>
<footer class="footer">
<section class="container">
<p>ZXing TypeScript Demo. Licensed under the <a target="_blank" href="https://github.com/zxing-js/library#license" title="MIT">MIT</a>.</p>
</section>
</footer>
</main>
<script type="text/javascript" src="https://unpkg.com/@zxing/library@latest"></script>
<script type="text/javascript">
window.addEventListener('load', function () {
const codeReader = new ZXing.BrowserQRCodeReader()
console.log('ZXing code reader initialized')
document.getElementById('decodeButton').addEventListener('click', () => {
const img = document.getElementById('img')
codeReader.decodeFromImage(img).then((result) => {
console.log(result)
document.getElementById('result').textContent = result.text
}).catch((err) => {
console.error(err)
document.getElementById('result').textContent = err
})
console.log(`Started decode for image from ${img.src}`)
})
})
</script>
</body>
</html>