bacon/bacon-qr-code

PHP library for generating QR codes with configurable error correction and multiple output renderers

Library
Composer
vv3.1.1
2,088stars
BSD-2-Clause

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
50/100Fair
Development Activity8
Maintenance20
Community72
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
75/100Good
Architecture80
Code Quality78
Innovation65
Learning Curve75

BaconQrCode is a pure-PHP QR code generator that handles the full encoding pipeline — data segmentation, Reed-Solomon error correction, and matrix placement — needed to produce a valid QR code, then renders the result through pluggable renderer backends (image, SVG, plain text, etc.). It’s widely used as the QR-generation engine behind two-factor authentication setup screens, ticketing systems, and payment/URL QR codes in PHP applications.

Because the encoder and renderer are cleanly separated, applications can generate a QR matrix once and output it as a PNG via Imagick, an SVG for the web, or raw ASCII for terminal display, without re-implementing the encoding logic for each format.

What You Get

  • Full QR code encoder (Encoder/) implementing data segmentation and Reed-Solomon error correction per the QR spec
  • Configurable error-correction levels (L/M/Q/H) trading data capacity for damage resistance
  • Pluggable renderer backends (Renderer/) for image (Imagick), SVG, and plain-text output
  • A Writer class tying encoding and rendering together into a single call
  • PSR-4 autoloaded, dependency-light (only ext-iconv and dasprid/enum required)

Common Use Cases

  • Generating TOTP/2FA setup QR codes for authenticator apps in PHP authentication systems
  • Producing scannable QR codes for event tickets, payment links, or URLs in web applications
  • Rendering QR codes as SVG for print-quality output or as images for on-screen display
  • Embedding QR generation in Laravel/Symfony packages as the underlying encoding engine

Under The Hood

Architecture - The library splits cleanly into src/Encoder/ (data segmentation, Reed-Solomon error correction, and QR matrix construction per the ISO/IEC 18004 spec), src/Renderer/ (backends that take an encoded matrix and produce image, SVG, or text output), and src/Common/ for shared value objects; Writer.php is the facade that composes an encoder and a renderer into a single writeString()-style call for consumers.

Tech Stack - PHP 8.1+, with ext-iconv for character-set handling during data segmentation and dasprid/enum for typed enum-like error-correction-level constants; ext-imagick is an optional suggested dependency for image rendering, keeping the core encoder dependency-free.

Code Quality - The test/ directory (17+ test files) uses PHPUnit with spatie/phpunit-snapshot-assertions and spatie/pixelmatch-php for pixel-level snapshot testing of rendered QR images — an appropriate testing strategy for a library where correctness ultimately means “does this render as a valid, scannable QR code,” not just unit-level assertions. PHP_CodeSniffer enforces style consistency.

API Design - The encoder/renderer separation is the main design decision: consumers call Encoder::encode() once and can then pass the result to any renderer, avoiding renderer-specific encoding logic and making it straightforward to add new output formats without touching the QR algorithm itself.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search