brzuchal/ansi-qr-code

PHP library for creating QR codes in ANSI format for terminal

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/brzuchal/ansi-qr-code

1.1.4 2025-11-19 10:14 UTC

This package is auto-updated.

Last update: 2025-11-19 10:14:45 UTC


README

A PHP library for generating QR codes in the terminal using ANSI escape codes.

PHP Version License

Terminal QR Demo

Command Line Tool

CLI Demo

Features

  • 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-code for matrix generation.
  • Static Analysis: Strict type checking with PHPStan (max level).
  • Coding Standard: Adheres to brzuchal/coding-standard.

Installation

composer require brzuchal/ansi-qr-code

Installation

One-liner (Recommended)

Installs the qr command to ~/.local/bin.

curl -s https://raw.githubusercontent.com/brzuchal/ansi-qr-code/1.1/install.sh | bash

Composer

composer global require brzuchal/ansi-qr-code

Usage

Command Line

After 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"

PHP Code

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;

Customizing Renderer

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');

Requirements

  • PHP ^8.3
  • bacon/bacon-qr-code ^2.0

License

MIT