forked from Dynamsoft/barcode-reader-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequirejs.html
More file actions
72 lines (65 loc) · 2.7 KB
/
requirejs.html
File metadata and controls
72 lines (65 loc) · 2.7 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
</head>
<body>
Choose image(s) to decode:
<input id="ipt-file" type="file" multiple accept="image/png,image/jpeg,image/bmp,image/gif">
<br><br>
<button id="btn-show-scanner">show scanner</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
<script>
// reader for decoding picture
let reader = null;
// scanner for decoding video
let scanner = null;
requirejs(['https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@7.5.0-v1/dist/dbr.js'], function(Dynamsoft){
// Please visit https://www.dynamsoft.com/CustomerPortal/Portal/TrialLicense.aspx to get a trial license.
Dynamsoft.BarcodeReader.productKeys = "PRODUCT-KEYS";
Dynamsoft.BarcodeReader.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@7.5.0-v1/dist/";
// Dynamsoft.BarcodeReader._bUseFullFeature = true; // Control of loading min wasm or full wasm.
// decode input picture
document.getElementById('ipt-file').addEventListener('change', async function(){
try{
reader = reader || await Dynamsoft.BarcodeReader.createInstance();
let resultsToAlert = [];
for(let i = 0; i < this.files.length; ++i){
let file = this.files[i];
resultsToAlert.push(i + '. ' + file.name + ":");
let results = await reader.decode(file);
console.log(results);
for(let result of results){
resultsToAlert.push(result.barcodeText);
}
}
alert(resultsToAlert.join('\n'));
}catch(ex){
alert(ex.message);
throw ex;
}
this.value = '';
});
// decode video from camera
document.getElementById('btn-show-scanner').addEventListener('click', async () => {
try{
scanner = scanner || await Dynamsoft.BarcodeScanner.createInstance();
scanner.onFrameRead = results => {
if(results.length){
console.log(results);
}
};
scanner.onUnduplicatedRead = (txt, result) => {
alert(result.barcodeFormatString + ': ' + txt);
};
await scanner.show();
}catch(ex){
alert(ex.message);
throw ex;
}
});
});
</script>
</body>
</html>