PHPackages                             phpdot/qrcode - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. phpdot/qrcode

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

phpdot/qrcode
=============

Coroutine-safe QR code generation with SVG, PNG and data-URI renderers for the PHPdot ecosystem.

v1.0.1(3w ago)02↓66.7%MITPHPPHP &gt;=8.4

Since Jun 8Pushed 1mo agoCompare

[ Source](https://github.com/phpdot/qrcode)[ Packagist](https://packagist.org/packages/phpdot/qrcode)[ RSS](/packages/phpdot-qrcode/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (12)Versions (3)Used By (0)

phpdot/qrcode
=============

[](#phpdotqrcode)

Coroutine-safe QR code generation for the PHPdot ecosystem. Encode any string to a QR symbol and render it as **SVG** (a pure string, no extension), **PNG** (GD), a raw **module matrix**, or an inline **`data:`URI** — through one immutable, injectable factory. Encoding is delegated to the battle-tested [`bacon/bacon-qr-code`](https://github.com/Bacon/BaconQrCode) (numeric, alphanumeric, byte and Kanji modes, ECI, all four error-correction levels, versions 1–40, automatic masking); everything bacon touches is fenced behind a single `Encoder`, and the rest of the package — the value objects, the renderers, the fluent builder — is plain PHPdot code.

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Architecture](#architecture)
- [Testing](#testing)
- [License](#license)

Requirements
------------

[](#requirements)

RequirementConstraintPHP`>= 8.5``ext-gd``*``bacon/bacon-qr-code``^3.0``ext-gd` is used only by the PNG renderer; SVG, the data URI, and the raw matrix need no extension.

Installation
------------

[](#installation)

```
composer require phpdot/qrcode
```

Usage
-----

[](#usage)

### One-call helpers

[](#one-call-helpers)

Inject `QrCodeFactory` and call a format helper — each encodes with sensible defaults and returns the bytes directly:

```
use PHPdot\QrCode\QrCodeFactory;

final class TicketController
{
    public function __construct(private readonly QrCodeFactory $qr) {}

    public function qr(string $ticketId): string
    {
        return $this->qr->svg("https://phpdot.com/t/{$ticketId}");
    }
}
```

`svg()`, `png()`, and `dataUri()` cover the common cases; `make()` returns the encoded `QrCode` value object without rendering, and `create()` opens a fluent build for anything more.

### The fluent builder

[](#the-fluent-builder)

`create()` returns an immutable `QrCodeBuilder` — every setter returns a new builder, so a configured builder is a safe reusable template. Terminal methods (`toSvg()`, `toPng()`, `toDataUri()`, `toMatrix()`, `encode()`) produce the output:

```
use PHPdot\QrCode\Color;
use PHPdot\QrCode\Enum\ErrorCorrection;

$png = $qr->create('WIFI:T:WPA;S:phpdot;P:secret;;')
    ->errorCorrection(ErrorCorrection::High)
    ->size(512)
    ->margin(2)
    ->foreground(Color::fromHex('#101828'))
    ->background(Color::fromHex('#f8fafc'))
    ->toPng();

file_put_contents('wifi.png', $png);
```

### Colors and options

[](#colors-and-options)

`Color` is an immutable RGBA value object with channels validated to `0–255`; `RenderOptions` carries the `size` (target square edge in pixels, default `300`) and `margin` (quiet-zone width in modules, default `4`):

```
use PHPdot\QrCode\Color;

Color::fromHex('#0b5');        // #rgb / #rrggbb / #rrggbbaa, '#' optional
Color::black();
Color::transparent();          // real alpha channel in the PNG

$svg = $qr->create('https://phpdot.com')
    ->background(Color::transparent())
    ->toSvg();
```

### Encoding and ECI

[](#encoding-and-eci)

Byte-mode content defaults to UTF-8 with an ECI segment, the specification-correct way to signal a non-ISO-8859-1 charset. Most modern scanners read it fine; for legacy hardware scanners that cannot, disable it with `eci(false)`. ASCII content (URLs, numbers) is unaffected.

```
$svg = $qr->create('https://phpdot.com')->eci(false)->toSvg();
```

Architecture
------------

[](#architecture)

`QrCodeFactory` is the injected `#[Singleton]` entry point; it hands out immutable `QrCodeBuilder`instances. A build asks `Encoder` — the single boundary to `bacon/bacon-qr-code` — to produce a `QrCode`carrying an immutable `Matrix`, then passes that matrix plus `RenderOptions` to a `RendererInterface`. The SVG renderer is a pure string (non-blocking, the default); the PNG renderer is a CPU-bound GD raster; the data-URI renderer wraps either and base64-encodes the result.

 ```
graph TD
    FACTORY["QrCodeFactory#[Singleton] — inject this"]
    BUILDER["QrCodeBuilderimmutable fluent build"]
    ENCODER["Encoderthe only bacon/bacon-qr-code boundary"]
    QRCODE["QrCode + Matrixreadonly value objects"]
    RENDERER["RendererInterface"]
    SVG["SvgRendererpure string, non-blocking"]
    PNG["PngRendererGD raster, CPU-bound"]
    URI["DataUriRendererwraps a renderer → data URI"]

    FACTORY --> BUILDER
    BUILDER --> ENCODER
    ENCODER --> QRCODE
    QRCODE --> RENDERER
    RENDERER --> SVG
    RENDERER --> PNG
    RENDERER --> URI
```

      Loading Testing
-------

[](#testing)

```
composer install
composer test        # PHPUnit (Unit + Integration)
composer analyse     # PHPStan, level max + strict rules
composer cs-check    # PHP-CS-Fixer
composer check       # All three
```

The PNG renderer is covered by a pixel round-trip test: a symbol is rendered, its pixels are read back, the matrix is reconstructed, and it is asserted equal to the source — so a renderer that painted the wrong cells fails even though the encoder itself is trusted.

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

This repository is a **read-only mirror**. The canonical source lives in [phpdot/monorepo](https://github.com/phpdot/monorepo); pull requests and issues are handled there: [pulls](https://github.com/phpdot/monorepo/pulls) · [issues](https://github.com/phpdot/monorepo/issues).

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance92

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Total

2

Last Release

25d ago

PHP version history (2 changes)v1.0.0PHP &gt;=8.3

v1.0.1PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/62e82421bda4b5d6ba9a47ba6d88caca060dcd0d1a2862f351f3a97657385db0?d=identicon)[phpdot](/maintainers/phpdot)

---

Top Contributors

[![phpdot](https://avatars.githubusercontent.com/u/252500?v=4)](https://github.com/phpdot "phpdot (1 commits)")

---

Tags

qrcodeqrsvgpngphpdot

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpdot-qrcode/health.svg)

```
[![Health](https://phpackages.com/badges/phpdot-qrcode/health.svg)](https://phpackages.com/packages/phpdot-qrcode)
```

###  Alternatives

[endroid/qr-code

Endroid QR Code

4.8k74.1M501](/packages/endroid-qr-code)[linkxtr/laravel-qrcode

A clean, modern, and easy-to-use QR code generator for Laravel

3720.4k](/packages/linkxtr-laravel-qrcode)[tuncaybahadir/quar

A simple QR Code generation tool for your projects with Laravel 10, 11, 12, 13 versions, php 8.2, 8.3, 8.4 and 8.5

80116.7k6](/packages/tuncaybahadir-quar)[akira/laravel-qrcode

A clean, modern, and easy-to-use QR code generator for Laravel

494.8k](/packages/akira-laravel-qrcode)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
