PHPackages                             xsuchy09/php-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. xsuchy09/php-qrcode

ActiveLibrary

xsuchy09/php-qrcode
===================

A QR code generator. PHP 7.2+

3.1.2(6y ago)07.8k↓50%MITPHPPHP ^7.2

Since Dec 11Pushed 6y agoCompare

[ Source](https://github.com/xsuchy09/php-qrcode)[ Packagist](https://packagist.org/packages/xsuchy09/php-qrcode)[ Docs](https://github.com/xsuchy09/php-qrcode)[ RSS](/packages/xsuchy09-php-qrcode/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (34)Used By (0)

xsuchy09/php-qrcode
===================

[](#xsuchy09php-qrcode)

Fork from [chillerlan/php-qrcode](https://github.com/chillerlan/php-qrcode).

A PHP7.2+ QR Code library based on the [implementation](https://github.com/kazuhikoarase/qrcode-generator) by [Kazuhiko Arase](https://github.com/kazuhikoarase), namespaced, cleaned up, improved and other stuff.

[![Packagist version](https://camo.githubusercontent.com/6dee90f03bc25c4b23ac4eef9c65f620e7a425a7224fdf5b94054b099d067c43/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f78737563687930392f7068702d7172636f64652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/xsuchy09/php-qrcode)[![License](https://camo.githubusercontent.com/8824831e0b75b8651c261454d9a3eea545945b70f97967d7008ad18a649453cd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f78737563687930392f7068702d7172636f64652e7376673f7374796c653d666c61742d737175617265)](https://github.com/xsuchy09/php-qrcode/blob/master/LICENSE)[![Travis CI](https://camo.githubusercontent.com/54263128ac82f82d1b38e47eeedeef8725f23cafbb0749768dc1b2aa1860e780/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f78737563687930392f7068702d7172636f64652e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/xsuchy09/php-qrcode)

Documentation
-------------

[](#documentation)

### Requirements

[](#requirements)

- PHP 7.2+
    - `ext-gd`, `ext-json`, `ext-mbstring`
    - optional `ext-imagick`

### Installation

[](#installation)

**requires [composer](https://getcomposer.org)**

Just run:

```
composer require xsuchy09/php-qrcode
```

Or edit your *composer.json* (note: replace `dev-master` with a [version boundary](https://getcomposer.org/doc/articles/versions.md))

```
{
	"require": {
		"php": "^7.2",
		"xsuchy09/php-qrcode": "dev-master"
	}
}
```

#### Manual installation

[](#manual-installation)

Download the desired version of the package from [master](https://github.com/xsuchy09/php-qrcode/archive/master.zip) or [release](https://github.com/xsuchy09/php-qrcode/releases) and extract the contents to your project folder. After that:

- run `composer install` to install the required dependencies and generate `/vendor/autoload.php`.
- if you use a custom autoloader, point the namespace `xsuchy09\QRCode` to the folder `src` of the package

Profit!

### Usage

[](#usage)

We want to encode this URI for a mobile authenticator into a QRcode image:

```
$data = 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net';

//quick and simple:
echo '';
```

 [![QR codes are awesome!](https://raw.githubusercontent.com/xsuchy09/php-qrcode/master/examples/example_image.png)](https://raw.githubusercontent.com/xsuchy09/php-qrcode/master/examples/example_image.png) [![QR codes are awesome!](https://raw.githubusercontent.com/xsuchy09/php-qrcode/master/examples/example_svg.png)](https://raw.githubusercontent.com/xsuchy09/php-qrcode/master/examples/example_svg.png)

Wait, what was that? Please again, slower!

### Advanced usage

[](#advanced-usage)

Ok, step by step. First you'll need a `QRCode` instance, which can be optionally invoked with a `QROptions` (or a [`SettingsContainerInterface`](https://github.com/chillerlan/php-settings-container/blob/master/src/SettingsContainerInterface.php), respectively) object as the only parameter.

```
$options = new QROptions([
	'version'    => 5,
	'outputType' => QRCode::OUTPUT_MARKUP_SVG,
	'eccLevel'   => QRCode::ECC_L,
]);

// invoke a fresh QRCode instance
$qrcode = new QRCode($options);

// and dump the output
$qrcode->render($data);

// ...with additional cache file
$qrcode->render($data, '/path/to/file.svg');
```

In case you just want the raw QR code matrix, call `QRCode::getMatrix()` - this method is also called internally from `QRCode::render()`. See also [Custom output modules](#custom-qroutputinterface).

```
$matrix = $qrcode->getMatrix($data);

foreach($matrix->matrix() as $y => $row){
	foreach($row as $x => $module){

		// get a module's value
		$value = $module;
		$value = $matrix->get($x, $y);

		// boolean check a module
		if($matrix->check($x, $y)){ // if($module >> 8 > 0)
			// do stuff, the module is dark
		}
		else{
			// do other stuff, the module is light
		}

	}
}
```

Have a look [in this folder](https://github.com/xsuchy09/php-qrcode/tree/master/examples) for some more usage examples.

#### Custom module values

[](#custom-module-values)

Previous versions of `QRCode` held only boolean matrix values that only allowed to determine whether a module was dark or not. Now you can distinguish between different parts of the matrix, namely the several required patterns from the QR Code specification, and use them in different ways.

The dark value is the module (light) value shifted by 8 bits to the left: `$value = $M_TYPE > 8 === $M_TYPE;

//for false (light)
$value === $M_TYPE;
```

...or you can perform a loose check, ignoring the module value

```
// for true
$value >> 8 > 0;

// for false
$value >> 8 === 0
```

See also `QRMatrix::set()`, `QRMatrix::check()` and [`QRMatrix` constants](#qrmatrix-constants).

To map the values and properly render the modules for the given `QROutputInterface`, it's necessary to overwrite the default values:

```
$options = new QROptions;

// for HTML, SVG and ImageMagick
$options->moduleValues = [
	// finder
	1536 => '#A71111', // dark (true)
	6    => '#FFBFBF', // light (false)
	// alignment
	2560 => '#A70364',
	10   => '#FFC9C9',
	// timing
	3072 => '#98005D',
	12   => '#FFB8E9',
	// format
	3584 => '#003804',
	14   => '#00FB12',
	// version
	4096 => '#650098',
	16   => '#E0B8FF',
	// data
	1024 => '#4A6000',
	4    => '#ECF9BE',
	// darkmodule
	512  => '#080063',
	// separator
	8    => '#AFBFBF',
	// quietzone
	18   => '#FFFFFF',
];

// for the image output types
$options->moduleValues = [
	512  => [0, 0, 0],
	// ...
];

// for string/text output
$options->moduleValues = [
	512  => '#',
	// ...
];
```

#### Custom `QROutputInterface`

[](#custom-qroutputinterface)

Instead of bloating your code you can simply create your own output interface by extending `QROutputAbstract`. Have a look at the [built-in output modules](https://github.com/chillerlan/php-qrcode/tree/master/src/Output).

```
class MyCustomOutput extends QROutputAbstract{

	// inherited from QROutputAbstract
	protected $matrix;      // QRMatrix
	protected $moduleCount; // modules QRMatrix::size()
	protected $options;     // MyCustomOptions or QROptions
	protected $scale;       // scale factor from options
	protected $length;      // length of the matrix ($moduleCount * $scale)

	// ...check/set default module values (abstract method, called by the constructor)
	protected function setModuleValues():void{
		// $this->moduleValues = ...
	}

	// QROutputInterface::dump()
	public function dump(string $file = null):string{
		$output = '';

		for($row = 0; $row < $this->moduleCount; $row++){
			for($col = 0; $col < $this->moduleCount; $col++){
				$output .= (int)$this->matrix->check($col, $row);
			}
		}

		return $output;
	}

}
```

In case you need additional settings for your output module, just extend `QROptions`...

```
class MyCustomOptions extends QROptions{
	protected $myParam = 'defaultValue';

	// ...
}

```

...or use the [`SettingsContainerInterface`](https://github.com/chillerlan/php-settings-container/blob/master/src/SettingsContainerInterface.php), which is the more flexible approach.

```
trait MyCustomOptionsTrait{
	protected $myParam = 'defaultValue';

	// ...
}
```

set the options:

```
$myOptions = [
	'version'         => 5,
	'eccLevel'        => QRCode::ECC_L,
	'outputType'      => QRCode::OUTPUT_CUSTOM,
	'outputInterface' => MyCustomOutput::class,
	// your custom settings
	'myParam'         => 'whatever value',
 ];

// extends QROptions
$myCustomOptions = new MyCustomOptions($myOptions);

// using the SettingsContainerInterface
$myCustomOptions = new class($myOptions) extends SettingsContainerAbstract{
	use QROptionsTrait, MyCustomOptionsTrait;
};
```

You can then call `QRCode` with the custom modules...

```
(new QRCode($myCustomOptions))->render($data);
```

...or invoke the `QROutputInterface` manually.

```
$qrOutputInterface = new MyCustomOutput($myCustomOptions, (new QRCode($myCustomOptions))->getMatrix($data));

//dump the output, which is equivalent to QRCode::render()
$qrOutputInterface->dump();
```

### API

[](#api)

#### `QRCode` methods

[](#qrcode-methods)

methodreturndescription`__construct(QROptions $options = null)`-see [`SettingsContainerInterface`](https://github.com/chillerlan/php-settings-container/blob/master/src/SettingsContainerInterface.php)`render(string $data, string $file = null)`mixed, `QROutputInterface::dump()`renders a QR Code for the given `$data` and `QROptions`, saves `$file` optional`getMatrix(string $data)``QRMatrix`returns a `QRMatrix` object for the given `$data` and current `QROptions``initDataInterface(string $data)``QRDataInterface`returns a fresh `QRDataInterface` for the given `$data``isNumber(string $string)`boolchecks if a string qualifies for `Number``isAlphaNum(string $string)`boolchecks if a string qualifies for `AlphaNum``isKanji(string $string)`boolchecks if a string qualifies for `Kanji`#### `QRCode` constants

[](#qrcode-constants)

namedescription`VERSION_AUTO``QROptions::$version``MASK_PATTERN_AUTO``QROptions::$maskPattern``OUTPUT_MARKUP_SVG`, `OUTPUT_MARKUP_HTML``QROptions::$outputType` markup`OUTPUT_IMAGE_PNG`, `OUTPUT_IMAGE_JPG`, `OUTPUT_IMAGE_GIF``QROptions::$outputType` image`OUTPUT_STRING_JSON`, `OUTPUT_STRING_TEXT``QROptions::$outputType` string`OUTPUT_IMAGICK``QROptions::$outputType` ImageMagick`OUTPUT_CUSTOM``QROptions::$outputType`, requires `QROptions::$outputInterface``ECC_L`, `ECC_M`, `ECC_Q`, `ECC_H`,ECC-Level: 7%, 15%, 25%, 30% in `QROptions::$eccLevel``DATA_NUMBER`, `DATA_ALPHANUM`, `DATA_BYTE`, `DATA_KANJI``QRDataInterface::$datamode`#### `QROptions` properties

[](#qroptions-properties)

propertytypedefaultalloweddescription`$version`int`QRCode::VERSION_AUTO`1...40the [QR Code version number](http://www.qrcode.com/en/about/version.html)`$versionMin`int11...40Minimum QR version (if `$version = QRCode::VERSION_AUTO`)`$versionMax`int401...40Maximum QR version (if `$version = QRCode::VERSION_AUTO`)`$eccLevel`int`QRCode::ECC_L``QRCode::ECC_X`Error correct level, where X = L (7%), M (15%), Q (25%), H (30%)`$maskPattern`int`QRCode::MASK_PATTERN_AUTO`0...7Mask Pattern to use`$addQuietzone`bool`true`-Add a "quiet zone" (margin) according to the QR code spec`$quietzoneSize`int4clamped to 0 ... `$matrixSize / 2`Size of the quiet zone`$outputType`string`QRCode::OUTPUT_IMAGE_PNG``QRCode::OUTPUT_*`built-in output type`$outputInterface`string`null`\*FQCN of the custom `QROutputInterface` if `QROptions::$outputType` is set to `QRCode::OUTPUT_CUSTOM``$cachefile`string`null`\*optional cache file path`$eol`string`PHP_EOL`\*newline string (HTML, SVG, TEXT)`$scale`int5\*size of a QR code pixel (SVG, IMAGE\_\*), HTML -&gt; via CSS`$cssClass`string`null`\*a common css class`$svgOpacity`float1.00...1`$svgDefs`string\*\*anything between [``](https://developer.mozilla.org/docs/Web/SVG/Element/defs)`$svgViewBoxSize`int`null`\*a positive integer which defines width/height of the [viewBox attribute](https://css-tricks.com/scale-svg/#article-header-id-3)`$textDark`string'🔴'\*string substitute for dark`$textLight`string'⭕'\*string substitute for light`$markupDark`string'#000'\*markup substitute for dark (CSS value)`$markupLight`string'#fff'\*markup substitute for light (CSS value)`$imageBase64`bool`true`-whether to return the image data as base64 or raw like from `file_get_contents()``$imageTransparent`bool`true`-toggle transparency (no jpeg support)`$imageTransparencyBG`array`[255, 255, 255]``[R, G, B]`the RGB values for the transparent color, see [`imagecolortransparent()`](http://php.net/manual/function.imagecolortransparent.php)`$pngCompression`int-1-1 ... 9`imagepng()` compression level, -1 = auto`$jpegQuality`int850 - 100`imagejpeg()` quality`$imagickFormat`string'png'\*ImageMagick output type, see `Imagick::setType()``$imagickBG`string`null`\*ImageMagick background color, see `ImagickPixel::__construct()``$moduleValues`array`null`\*Module values map, see [Custom output modules](#custom-qroutputinterface) and `QROutputInterface::DEFAULT_MODULE_VALUES`#### `QRMatrix` methods

[](#qrmatrix-methods)

methodreturndescription`__construct(int $version, int $eclevel)`--`matrix()`arraythe internal matrix representation as a 2 dimensional array`version()`intthe current QR Code version`eccLevel()`intcurrent ECC level`maskPattern()`intthe used mask pattern`size()`intthe absoulute size of the matrix, including quiet zone (if set). `$version * 4 + 17 + 2 * $quietzone``get(int $x, int $y)`intreturns the value of the module`set(int $x, int $y, bool $value, int $M_TYPE)``QRMatrix`sets the `$M_TYPE` value for the module`check(int $x, int $y)`boolchecks whether a module is true (dark) or false (light)#### `QRMatrix` constants

[](#qrmatrix-constants)

namelight (false)dark (true)description`M_NULL`0-module not set (should never appear. if so, there's an error)`M_DARKMODULE`-512once per matrix at `$xy = [8, 4 * $version + 9]``M_DATA`41024the actual encoded data`M_FINDER`61536the 7x7 finder patterns`M_SEPARATOR`8-separator lines around the finder patterns`M_ALIGNMENT`102560the 5x5 alignment patterns`M_TIMING`123072the timing pattern lines`M_FORMAT`143584format information pattern`M_VERSION`164096version information pattern`M_QUIETZONE`18-margin around the QR Code`M_LOGO`20-space for a logo image (not used yet)`M_TEST`25565280test value### Notes

[](#notes)

The QR encoder, especially the subroutines for mask pattern testing, can cause high CPU load on increased matrix size. You can avoid a part of this load by choosing a fast output module, like `OUTPUT_IMAGE_*` and setting the mask pattern manually (which may result in unreadable QR Codes). Oh hey and don't forget to sanitize any user input!

### Disclaimer!

[](#disclaimer)

I don't take responsibility for molten CPUs, misled applications, failed log-ins etc.. Use at your own risk!

#### Trademark Notice

[](#trademark-notice)

The word "QR Code" is registered trademark of *DENSO WAVE INCORPORATED*

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 98.3% 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 ~46 days

Recently: every ~73 days

Total

30

Last Release

2455d ago

Major Versions

1.2.2 → 2.0.02017-12-24

1.0.8 → 2.0.22018-01-21

2.0.6 → 3.0.02018-09-19

PHP version history (3 changes)1.0.0PHP &gt;=5.6.0

1.1.1PHP &gt;=7.0.3

3.0.0PHP ^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/bfb9263df3f7fbc25d3d7645fc4a68878972f9e6e0056e12820a491c1f2b4a64?d=identicon)[xsuchy09](/maintainers/xsuchy09)

---

Top Contributors

[![codemasher](https://avatars.githubusercontent.com/u/592497?v=4)](https://github.com/codemasher "codemasher (291 commits)")[![joshstoik1](https://avatars.githubusercontent.com/u/403248?v=4)](https://github.com/joshstoik1 "joshstoik1 (2 commits)")[![darthmaim](https://avatars.githubusercontent.com/u/2511547?v=4)](https://github.com/darthmaim "darthmaim (1 commits)")[![kmvan](https://avatars.githubusercontent.com/u/3839554?v=4)](https://github.com/kmvan "kmvan (1 commits)")[![xsuchy09](https://avatars.githubusercontent.com/u/1107359?v=4)](https://github.com/xsuchy09 "xsuchy09 (1 commits)")

---

Tags

qr codeqrcodeqrphpqrcodeqrcode-generator

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[chillerlan/php-qrcode

A QR Code generator and reader with a user-friendly API. PHP 8.4+

2.4k28.9M208](/packages/chillerlan-php-qrcode)[endroid/qr-code

Endroid QR Code

4.8k67.6M348](/packages/endroid-qr-code)[milon/barcode

Barcode generator like Qr Code, PDF417, C39, C39+, C39E, C39E+, C93, S25, S25+, I25, I25+, C128, C128A, C128B, C128C, 2-Digits UPC-Based Extention, 5-Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI (Variation of Plessey code)

1.5k13.3M39](/packages/milon-barcode)[pragmarx/google2fa-qrcode

QR Code package for Google2FA

12124.6M37](/packages/pragmarx-google2fa-qrcode)[2amigos/qrcode-library

QrCode Generator

2201.5M21](/packages/2amigos-qrcode-library)[mpdf/qrcode

QR code generator for mPDF

492.7M41](/packages/mpdf-qrcode)

PHPackages © 2026

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