Last year I needed barcodes for a warehouse inventory system. I assumed generating them was trivial. I was completely wrong.
The GS1 Rabbit Hole
GS1 specifications define exactly how each format encodes data. UPC-A isn't just "12 digits" — the first digit is a category code, the last is a check digit computed using a specific modulo-10 algorithm.
I built a client-side barcode generator at genbarcode.org that handles 6 formats with no server uploads.
EAN-13 Check Digit
The 13th digit is calculated as: (10 - (odd_positions + even_positions * 3) % 10) % 10. Getting this wrong means retail scanners reject the barcode. I validated against GS1's official documentation.
Code 128: Three Character Sets in One
Unlike UPC/EAN, Code 128 has three character sets (A, B, C) and switches between them. Set C compresses digit pairs for double density. The switching logic tracks which set you're in and inserts shift codes when crossing boundaries.
SVG vs PNG for Barcodes
A 1200dpi SVG renders cleanly on any printer. The Canvas API handles PNG well, but SVG requires programmatic path generation based on GS1 width specs.
Canvas-based image tools like svg2png.org and webp2png.io have similar precision requirements — one pixel wrong produces visibly broken output.
If you work with barcodes, validate against physical scanners, not just visual inspection.
Top comments (0)