forked from yugasun/qrcode-decoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.html
60 lines (57 loc) · 2.28 KB
/
image.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>QrcodeDecoder - Image</title>
</head>
<body>
<section>
<h3>Same domain image</h3>
<img src="./assets/qrcode.png" alt="qr code" /><br />
<button id="decode1">Decode!</button><br />
<span id="result1"></span><br />
</section>
<hr />
<section>
<h3>Different domain image</h3>
<button id="decode2">Decode!</button><br />
<span id="result2"></span><br />
</section>
<script src="./lib/vconsole.min.js"></script>
<script src="./index.aio.min.js"></script>
<script type="module">
var vConsole = new VConsole();
console.log("Hello world");
function main() {
var qr = new QrcodeDecoder();
var btn1 = document.querySelector("button#decode1");
var btn2 = document.querySelector("button#decode2");
var result1 = document.querySelector("#result1");
var result2 = document.querySelector("#result2");
var img = document.querySelector("img");
btn1.onclick = async () => {
// you can also decode from image path
// const code = await qr.decodeFromImage('./assets/qrcode.png');
const code = await qr.decodeFromImage(img);
console.log(code);
result1.innerText = code.data;
};
btn2.onclick = async () => {
// you can also decode from image path
// const code = await qr.decodeFromImage('./assets/qrcode.png');
const code = await qr.decodeFromImage(
"https://yugasun.com/static/wechat.jpg",
{
crossOrigin: "anonymous"
}
);
console.log(code);
result2.innerText = code.data;
};
}
main();
</script>
</body>
</html>