primer / phpqrcode
A modern implementaion of QR code 2D barcode generator. Pure-php LGPL implementation based on https://phpqrcode.sourceforge.net, itself based on C libqrencode by Kentaro Fukuchi.
Requires
- php: >=7.4
- ext-gd: *
- ext-zlib: *
Requires (Dev)
- nunomaduro/phpinsights: ^2.5
- php-mock/php-mock-phpunit: ^2.15
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^8.5
- thiagolp90/qr-reader: ~1
This package is auto-updated.
Last update: 2026-08-25 20:30:36 UTC
README
PHP QRCode Generator Library for php.
A modern implementaion of QR code 2D barcode generator. Pure-php LGPL implementation based on inital phpqrcode, itself based on C libqrencode.
Installation
Type on the terminal
composer require primer/phpqrcode
Or, by adding this entry on the composer.json file
{
"require": {
"primer/phpqrcode": "~1"
}
}
Usage
Encode "data" into a png file:
QRcode::png("data", "path/to/file.png");
Options
QRcode::png($text, $outfile , correctionLevel: QRConstants::QR_ECLEVEL_L, size: 3, margin: 4, saveandprint: false);
Correction Level
(int) correction level, fom the lowest to highest:
QRConstants::QR_ECLEVEL_L0QRConstants::QR_ECLEVEL_M1QRConstants::QR_ECLEVEL_Q2QRConstants::QR_ECLEVEL_H3
Size
(int) Pixel size
Margin
(int) Raw silent zone (margin zone = raw * size)
Save and Print
(bool) Use saveAndPrint (bool) option to send to the browser both http header and image content.
Settings
This package automatically determines the best mode, but user can force to one of these modes :
QRConstants::QR_MODE_NUM: Force Numeric ModeQRConstants::QR_MODE_AN: Force Alpha-Numeric ModeQRConstants::QR_MODE_8: Force BYTE8 Mode (utf8)QRConstants::QR_MODE_KANJI: Force Kanji Mode (Shift-JIS)
Exemple :
QRSettings::forceMode(QRConstants::QR_MODE_8);
For experts,
user can also manipulate mask options,
see QRSettings::setDefaultMask(...); and QRSettings::setFindBestMask(...);
Minimum requirements
- PHP 7.3 for 1.2.x versions and below
- PHP 7.4 for 1.4.x versions and later
Credits
- Kentaro Fukuchi: for inital libqrencode C Lib (kentaro@megaui.net)
- Dominik Dzienia: for https://phpqrcode.sourceforge.net (deltalab@poczta.fm)
