バーコードスキャンライブラリQuaggaJSのブラウザ実装です。日本語の解説はブログ:「QuaggaJSを使ってブラウザでバーコードスキャン」に載せています。
A browser implementation of the barcode scan library QuaggaJS
-
import QuaagaJS
-
import WebRTC adapter(Optional)
-
import or copy barcodescanner.js
-
write html
<div clas="control"><input type="tel" id="barcode-input" maxlength="13" /><button onClick="toggleScan()">start/stop</button></div>
<div id="barcode-wrapper" style="visibility: hidden; border: 2px solid #099;">
<canvas id="barcode-view"></canvas>
<p id="message">initializing camera</p>
</div>
-
make instance in script like this
const barcodescanner = new ( videoSizeW, videoSizeH, viewSizeW, viewSizeH, targetSizeW, targetSizeH, borderLineSize, scanInterval, validationCnt);
- videoSize: Background video size.
- viewSize: View in HTML size.
- targetSize: Area of sending QuaagaJS
- borderLineSize: guide line size
- scanInterval: Interval to send to QuaagaJS(milliseconds)
- validationCnt: If the same code value is obtained the specified number of times, it is considered successful.
The html button event calls the method in the barcodescanner.js class b to window.togglescan