A PHP library for generating QR codes in the terminal using ANSI escape codes.
- ANSI Renderer: Uses half-block characters (
▀,▄,█) and ANSI colors to render high-resolution QR codes in the terminal. - ASCII Renderer: Fallback renderer using full block characters (
██) and spaces for broader compatibility. - Auto-detection: Automatically selects the best renderer based on terminal capabilities (TTY,
NO_COLOR,TERM). - Zero Dependencies: Only requires
bacon/bacon-qr-codefor matrix generation. - Static Analysis: Strict type checking with PHPStan (max level).
- Coding Standard: Adheres to
brzuchal/coding-standard.
composer require brzuchal/ansi-qr-codeInstalls the qr command to ~/.local/bin.
curl -s https://raw.githubusercontent.com/brzuchal/ansi-qr-code/1.1/install.sh | bashcomposer global require brzuchal/ansi-qr-codeAfter installing the package globally or in a project, you can use the qr command:
# If installed globally
qr "https://github.com/brzuchal/ansi-qr-code"
# If installed in a project
vendor/bin/qr "Your text here"use Brzuchal\TerminalQr\TerminalQrCode;
$qr = new TerminalQrCode();
// Write directly to STDOUT
$qr->write('https://github.com/brzuchal/ansi-qr-code');
// Or get the rendered string
$output = $qr->render('https://github.com/brzuchal/ansi-qr-code');
echo $output;You can choose between AnsiRenderer (default) and AsciiRenderer:
use Brzuchal\TerminalQr\TerminalQrCode;
use Brzuchal\TerminalQr\Renderer\AsciiRenderer;
// Use ASCII renderer (full blocks)
$qr = new TerminalQrCode(new AsciiRenderer());
$qr->write('https://example.com');- PHP ^8.3
- bacon/bacon-qr-code ^2.0
MIT

