bacon/bacon-qr-code
PHP library for generating QR codes with configurable error correction and multiple output renderers
Repository Health
Technical Analysis
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
Writerclass tying encoding and rendering together into a single call - PSR-4 autoloaded, dependency-light (only
ext-iconvanddasprid/enumrequired)
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.
Used by 4 apps in this directory
Craft CMS
CMS
A developer-first PHP CMS with clean-slate content modeling, auto-generated GraphQL API, and a four-tier edition system that scales from solo projects to enterprise deployments.
Invoice Ninja
Invoicing Finance · Project Management
Self-hostable invoicing, time-tracking, and multi-gateway payment platform for freelancers and small businesses, with built-in e-invoicing compliance for EU and global standards.
Passbolt API
Password Manager · Security
Self-hosted, end-to-end encrypted password manager API built for teams who demand full ownership of their credentials.
Pixelfed
Social Media
A decentralized, self-hosted photo sharing platform built on ActivityPub for the open Fediverse.