Shim

Barcodes

Seven retail and logistics symbologies, with every check digit calculated and verified before the code is drawn. A barcode that will not scan is refused rather than rendered.

About barcodes

Barcodes look interchangeable and are not. EAN-13 is what is on almost everything sold in shops outside North America. UPC-A is the same idea for the United States and Canada, and is structurally an EAN-13 with a leading zero, which is why a European scanner reads an American product without being told anything. EAN-8 and UPC-E are short forms for packs with no room for the full symbol. ITF-14 goes on the outer case rather than the item. Code 39 and Code 128 hold letters as well as digits and are for your own numbering rather than for retail.

The thing they have in common is the part worth being careful about. Most of these end in a check digit worked out from the digits before it, and a scanner uses it to catch a misread. If it does not match, the scanner rejects the read rather than reporting the wrong number. A generator that calculates it wrongly produces a label that looks right, prints right, and fails at the till, and that is usually discovered after a print run.

Every check digit here is calculated when you supply the data digits and verified when you supply the full code. Where it does not match, the code is refused with a message saying what it should have been, rather than drawn anyway. The algorithm is tested against published reference values rather than against this implementation, because a test that derives its expectation from the code it tests proves only that the code agrees with itself.

UPC-E deserves a warning. Its six printed digits are a compressed form of a full twelve digit UPC-A, and the check digit belongs to the expanded version, not to the six you can see. Computing it from what is printed is the single most common way to produce an invalid UPC-E.

Output is SVG throughout. A bitmap barcode scaled up blurs its bars and scanners give up, so offering a PNG would be offering a format that exists to be misused.