This repository has been archived by the owner on May 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
70 lines (60 loc) · 2.36 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
<!DOCTYPE html>
<html>
<head>
<title>QR code reader browser upload image</title>
<style>
#preview img {
border: 1px solid black;
float: left;
margin: 0 1em 1em 0;
width: 10em;
}
</style>
</head>
<body>
<h1>QR code reader using the FileReader API</h1>
<h2>Upload file</h2>
<input type="file" id="upload">
<h2>Result</h2>
<div id="preview"></div>
<!-- https://github.com/edi9999/jsqrcode -->
<script type="text/javascript" src="qrcode.min.js"></script>
<script type="text/javascript">
(function() {
'use strict';
var upload = document.getElementById('upload');
var preview = document.getElementById('preview');
var qr = new QrCode();
qr.callback = function(err, result) {
var span = document.querySelector('span') || document.createElement('span');
if(result){
span.textContent = JSON.stringify(result)
}
else{
span.textContent = 'Error! See error message in console!';
console.error(err);
}
preview.appendChild(span);
}
upload.addEventListener('change', function() {
for (var i = 0; i < this.files.length; i++) {
var file = this.files[i];
var imageType = /^image\//;
if (!imageType.test(file.type)) {
throw new Error('File type not valid');
}
var reader = new FileReader();
reader.addEventListener('load', function() {
var img = document.querySelector('img') || document.createElement('img');
img.src = this.result;
preview.appendChild(img);
qr.decode(this.result);
}.bind(reader), false);
reader.readAsDataURL(file);
}
}, false);
})();
</script>
<a href="https://github.com/miguelmota/qrcode-reader" target="_blank"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
</body>
</html>