-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsample.html
79 lines (78 loc) · 2.67 KB
/
sample.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
<!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">
#result {
display: none;
max-width: 300px;
max-height: 300px;
border-radius: 12px;
}
#qrCode {
display: none;
}
body {
text-align: center;
font-family: Arial, Helvetica, sans-serif;
height: 100%;
}
#captureButton {
display: block;
margin-bottom: 32px;
}
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">
<img id="result" alt="ID card image" />
<a id="captureButton" href="javascript:void(0)">Capture image</a>
<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 "./dist/imageCapture.min.js"
import generateQRCode from "./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
})
}
document.querySelector("#captureButton").onclick = function() {
captureImage({"size":{"width":600,"height":600},"scaling":""}).then(function(dataURL) {
var img = document.querySelector("#result")
img.src = dataURL
img.style.display = "inline-block"
}).catch(function(error) {
alert("Capture failed"+(error && error.message ? ": "+error.message : ""))
})
}
</script>
</body>
</html>