-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathid-capture-demo.html
99 lines (98 loc) · 3.58 KB
/
id-capture-demo.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Image capture sample</title>
<style type="text/css">
div.button {
cursor: pointer;
margin-bottom: 32px;
border-radius: 12px;
border: 1px solid #eee;
width: 240px;
padding: 8px;
text-align: center;
position: relative;
left: 0px;
right: 0px;
margin-left: auto;
margin-right: auto;
}
#qrCode {
display: none;
}
body {
text-align: center;
font-family: Arial, Helvetica, sans-serif;
height: 100%;
}
a, summary {
color: #36c;
}
#capture {
text-align: center;
position: relative;
top: 50%;
transform: translateY(-50%);
}
#content {
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
}
</style>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/englishextra/[email protected]/js/qrjs2.min.js"></script>
</head>
<body>
<div id="content">
<div id="capture">
<h1>Driver's licence</h1>
<div class="button front">
<a class="capture">Scan front</a>
<span class="result"></span>
</div>
<div class="button back">
<a class="capture">Scan back</a>
<span class="result"></span>
</div>
<details id="qrCode">
<summary>Use another device</summary>
<img alt="QR code" />
<p>Scan the QR code to continue on a mobile</p>
</details>
</div>
</div>
<script type="module">
import captureImage from "https://cdn.jsdelivr.net/gh/AppliedRecognition/[email protected]/dist/imageCapture.min.js"
import generateQRCode from "https://cdn.jsdelivr.net/gh/AppliedRecognition/[email protected]/dist/qrCodeGenerator.min.js"
if (location.hash != "#fromqrcode") {
generateQRCode(location.href+"#fromqrcode").then(function(qrCode) {
document.querySelector("#qrCode img").src = qrCode
document.querySelector("#qrCode").style.display = "block"
}).catch(function(error) {
// Ignore
})
}
var photos = {}
document.querySelectorAll("div.button").forEach(function(button) {
button.onclick = function() {
captureImage().then(function(dataURL) {
button.querySelector("span.result").innerText = "(photo taken)"
if (button.classList.contains("front")) {
photos["front"] = dataURL
} else {
photos["back"] = dataURL
}
if (Object.keys(photos).length == 2) {
alert("Thank you. All done.")
}
}).catch(function(error) {
alert("Capture failed"+(error && error.message ? ": "+error.message : ""))
})
}
})
</script>
</body>
</html>