buntine / barcoders

A barcode encoding library for the Rust programming language
Apache License 2.0
164 stars 24 forks source link

Invalid EAN13 image generation? #23

Closed sergeyshaykhullin closed 2 years ago

sergeyshaykhullin commented 3 years ago

I have a barcode 2000926398005. I tried to generate an image from it

Same as example

let barcode = EAN13::new("2000926398005").unwrap();
let png = Image::png(50);
let encoded = barcode.encode();

let bytes = png.generate(&encoded[..]).unwrap();

let file = File::create(&Path::new("my_barcode.png")).unwrap();
let mut writer = BufWriter::new(file);
writer.write(&bytes[..]).unwrap();

Expected image: 2000926398005 Last - 1 fat, 2 thin

Barcoders generated image: my_barcode Last - 2 fat, 3 thin

Barcoders generated images is not scannable

sergeyshaykhullin commented 3 years ago

I tried values from test but...

image

Scanned barcode is not the same/ It has a 9 at the end image

tscott0 commented 3 years ago

I have a similar issue with EAN8 codes. In my experience, dropping the last digit (the checkdigit) provides a workaround.

let ean = "200092639800";
let barcode = EAN13::new(ean).unwrap();

The above code outputs this barcode, which seems to match yours. Scanning it returns 2000926398005 too.

200092639800

sergeyshaykhullin commented 2 years ago

Workaround is found. Don't think that providing barcodes without chechdigit is a good idea. Maybe EAN13::with_check_digit(ean) needed.

Closing for now