Barcode Generation Guide

2026-05-05·6 min read·Image

Barcode Encoding Standards

Barcodes are graphic identifiers that arrange black bars and white spaces of varying widths according to specific encoding rules to represent a set of information. The most common barcode standards include: EAN-13 (European Article Numbering, 13 digits, for retail products), UPC-A (Universal Product Code, 12 digits), Code 128 (high-density barcode, supporting all ASCII characters), and Code 39 (alphanumeric mixed encoding).

Choosing the appropriate barcode standard depends on the use case: retail products use EAN-13 or UPC-A; logistics tracking uses Code 128 or GS1-128; asset management uses Code 39; ISBN book numbers use EAN-13 special variants. Each standard has a fixed checksum algorithm to ensure scanning accuracy.

Barcode Generation Implementation

// JavaScript using JsBarcode library
import JsBarcode from 'jsbarcode';

// Generate barcode on Canvas
const canvas = document.getElementById('barcode');
JsBarcode(canvas, '1234567890128', {
  format: 'EAN13',
  width: 2,
  height: 100,
  displayValue: true,
  fontSize: 20,
  margin: 10
});

// Generate Code 128 barcode
JsBarcode('#barcode128', 'Hello World 123', {
  format: 'CODE128',
  lineColor: '#000',
  background: '#fff'
});

// Python using python-barcode library
// import barcode
// from barcode.writer import ImageWriter
// ean = barcode.get('ean13', '123456789012', writer=ImageWriter())
// ean.save('barcode')

Scanning and Recognition

Barcode scanning is divided into hardware scanners and software scanning. Hardware scanners use optical sensors to read and decode barcodes, suitable for retail checkout scenarios. Software scanning uses smartphone cameras or computer cameras, identifying barcodes through image processing algorithms. The modern ZXing (Zebra Crossing) library is an open-source barcode recognition library supporting multiple formats.

To implement barcode scanning in web applications, you can use QuaggaJS or html5-qrcode libraries. These libraries use the WebRTC API to access cameras for real-time barcode detection and decoding. In practice, consider factors like lighting conditions, scanning angle, and barcode clarity that affect recognition rates.

Recommended Tools

JsBarcode is a JavaScript barcode generation library. Barcode Generator is an online barcode generation tool. ZXing is an open-source barcode recognition library. python-barcode is a Python barcode generation library.