0

I am trying to implement QuaggaJS in a static file way, but clearly I am missing something. I am very new to javascript and as such hoping I am missing something very simple. Assuming i have a .jpg file in the same directory as this code , named 123456.jpg, I want the code to simply return the barcode value as an alert. Any help greatly appreciated (and totally ready to be blasted for my lack of understanding of javascript!)

My code is below:

<script src="http://www.myserver.com/v3/javascripts/jquery-2.0.0.min.js" type="text/javascript"></script>
<script src="js/quagga.min.js" type="text/javascript"></script>

<script>

Quagga.decodeSingle({
    decoder: {
        readers: ["code_39_reader"] // List of active readers
    },
    locate: true, // try to locate the barcode in the image
    src: '123456.jpg' // or 'data:image/jpg;base64,' + data
}, function(result){
    if(result.codeResult) {
        console.log("result", result.codeResult.code);
        alert(result.codeResult.code);
    } else {
        console.log("not detected");
        alert("not detected");
    }
});


</script>
rdel
  • 155
  • 1
  • 1
  • 10

1 Answers1

0

Maybe clumsy...but I got the following to decode a Code_39 barcode in a static .jpg file located in same directory, on page load:

<div>
    <div id="resultdiv">scanning... </div>
</div>


<script src="../js/quagga.js" type="text/javascript"></script>
<script type="text/javascript">

    var Quagga = window.Quagga;
    var App = {
        _scanner: null,
        init: function() {

            this.decode();
        },
        decode: function(file) {
            Quagga
                .decoder({readers: ['code_39_reader']})
                .locator({patchSize: 'x-small'})
                .fromSource('converted.jpg', {size: 1920})
                .toPromise()
                .then(function(result) {
                    document.getElementById("resultdiv").innerHTML=result.codeResult.code; 
                })
                .catch(function() {
                    document.getElementById("resultdiv").innerHTML= "Not Found"; 
                })

        }
    };
    App.init();

</script>
rdel
  • 155
  • 1
  • 1
  • 10