manuels / unix-toolbox.js-exact-image

ExactImage's bardecode ported to JS
http://manuels.github.com/unix-toolbox.js
61 stars 21 forks source link

I don't get last character from barcode #1

Closed emehmet closed 11 years ago

emehmet commented 11 years ago

Hi,

i have 13 cahacter barcode image. i reading this barcode image but last character is lost.????

and even the case in your demo page.

manuels commented 11 years ago

That's simple: the last character is not an information, it's a checksum

emehmet commented 11 years ago

Thanks for your reply.

But at our barcode systems need to last character.

such as barcode image at Follow links:

http://tobeytailor.s3.amazonaws.com/get_barcode_from_image/index.html

manuels commented 11 years ago

Exact Image's bardecode does not provide it, but you can easily calculate that character: https://en.wikipedia.org/wiki/EAN-13

emehmet commented 11 years ago

Thank you. I solved this problem.

manuels commented 11 years ago

No problem. You can share your code here if you like ;)

emehmet commented 11 years ago
function calculateBarcodeWithChecksum(barcode) {
            var no = barcode;
            var sequence_ean13= [1,3];
            var sums = 0;

            var no_array = no.split("");

            for (var i = 0; i < no_array.length; i++) {
                   sums += no_array[i] *  sequence_ean13[i % 2];
            }

            var checksum = 10 - (sums % 10);
            if(checksum == 10){
            checksum = 0;
            }
            var ean_code = no+checksum;
            return ean_code;
}