Frontend Engineering

Deep Dive into QR Code Generation: Error Correction Levels and SVG Canvas Rendering

Understand Reed-Solomon error correction, masking patterns, and how to embed custom logos into QR codes without breaking camera readability.

Quick Response (QR) codes have transitioned from simple inventory barcodes into the universal bridge connecting physical reality with digital services—from UPI payments in India to event tickets and Wi-Fi access.

While generating a basic QR code requires just a few lines of code with an off-the-shelf library, engineering a production studio that allows custom colors, gradient patterns, and embedded company logos requires understanding the underlying mathematical error correction architecture.


1. Reed-Solomon Error Correction Explained

A QR code is not just an image; it is an error-tolerant matrix of binary modules. QR standards define four distinct Error Correction levels using the Reed-Solomon polynomial error correction algorithm:

LevelError ToleranceRecoverable DamageRecommended Use Case
L (Low)~7%Minor scratch toleranceClean digital screens, maximum data density
M (Medium)~15%Standard print useDefault for marketing links and menus
Q (Quartile)~25%Heavy wear toleranceFactory floors, shipping labels
H (High)~30%Highest redundancyMandatory when embedding central logos
When you overlay a brand logo in the center of a QR code, you are effectively destroying 10% to 20% of the code's central data modules. If the QR code was generated with Level L, the code becomes unreadable. Level H must always be enforced when custom branding is applied.

2. The Safe Logo Area (The 20% Rule)

Even with Level H error correction (30% redundancy), you should never place a logo that covers more than 20% of the total surface area. Exceeding 20% risks encroaching on critical timing patterns, alignment markers, or version information bits.
export function calculateMaxLogoSize(qrSizePx: number): number {
  // Safe maximum is 20% of width and height
  return Math.floor(qrSizePx * 0.22);
}

Always render a solid background or border radius around the logo to ensure that nearby dark QR code modules do not bleed into the logo's boundaries, confusing barcode scanner cameras.


3. Vector vs Canvas Rendering

  • Canvas Rendering: Excellent for fast raster image exports (JPEG, PNG) for mobile sharing.
  • SVG Vector Rendering: Essential for print shops and billboard scaling. Because SVGs describe paths and geometry mathematically, the resulting QR code can be scaled to billboard proportions without losing edge contrast.
```
#QR Code#Algorithms#SVG#TypeScript#Web Development
Shashank Dubey

Written by Shashank Dubey

Software Engineer specializing in Java Spring Boot, Node.js, React, distributed microservices, and enterprise cloud systems at National Informatics Centre (NIC), Government of India.

View Full Bio & Credentials →


Related In-Depth Engineering Guides