apirone / php-qr-code
Generate QR-codes from a single PHP file.
Installs: 8 120
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 140
pkg:composer/apirone/php-qr-code
Requires
- ext-gd: *
This package is auto-updated.
Last update: 2025-10-19 11:28:11 UTC
README
- Generate QRcode from a single PHP file. MIT license.
- Output to raw PNG or base64 encoded data
Install
composer require apirone/php-qr-code
Usage
require_once('../vendor/autoload.php'; use Apirone\Lib\PhpQrCode\QrCode; // Quick static method with base64 encoded PNG $data = 'Lorem ipsum dolor sit amet'; $options = [ 's' => 'qrm', 'fc' => '#000000', 'bc' => '#FFFFFF', // ... ]; $base64_qr_encoded = QrCode::png($data, $options); echo '<img src="' . $base64_qr_encoded . '"> '; // Create and use qr instant $qr = QRCode::init($data, $options); // $data & $options are optional // Also you can use chain to set some options (not all) $options['s'] = 'qrq'; $image_encoded = $qr->data($data)->options($options)->base64(); echo '<img src="' . $image_encoded . '"> '; $image_raw = QRCode::init() ->data($data) ->levelHigh() ->density(0.5) ->raw(); echo '<img src="data:image/png;base64,' . base64_encode($image_raw) . '"> ';
Options
Use options array to initialize class:
$options = [ 's' => 'qrl', 'fc' => '#000000', 'bc' => '#FFFFFF', // ... ];
Available options keys
You can define option as [key => value, ...] or use the option name as a property $qr->s = 'qrl'
-
s- QR error correction level. Available values:qrl- Level L (Low) 7% of data bytes can be restored.qrm- Level M (Medium) 15% of data bytes can be restored.qrq- Level Q (Quartile) 25% of data bytes can be restored.qrh- Level H (High) 30% of data bytes can be restored.
-
w- Width of image. Overridessforsx. -
h- Height of image. Overridessforsy. -
sf- Scale factor. Default 4. -
sx- Horizontal scale factor. Overridessf. -
sy- Vertical scale factor. Overridessf. -
p- Padding. Default is 0. -
pv- Top and bottom padding. Default is value of `p``. -
ph- Left and right padding. Default is value ofp. -
pt- Top padding. Default is value ofpv. -
pl- Left padding. Default is value ofph. -
pr- Right padding. Default is value ofph. -
pb- Bottom padding. Default is value ofpv. -
fc- Foreground color in#RRGGBBformat. -
bc- Background color in#RRGGBBformat. -
md- Module density. A number between 0 and 1. Default is 1. -
wq- Width of quiet area units. Default is 1. Use 0 to suppress quiet area. -
wm- Width of narrow modules and spaces. Default is 1.
Methods
Init methods. Static.
png($data, $options = [])- Convenience method to quickly generate an base64 encoded PNG. Static.init($data = '', $options = [])- Init QR code instance. Static.
Set error correction levels
levelLow()- Setsoption toqrl.levelMid()- Setsoption toqrm.levelQrt()- Setsoption toqrq.levelHigh()- Setsoption toqrh.levelAuto()- Unsetsoption.
Some parameters setup methods
Call methods without params to clear options value.
data($data = '')- Set QR code dataoptions($options = [])- Set QR code optionssize($size = null)- Generated image size. Sets bothhandwoptions to the same value.scale($scale = null)- Setsfoption value.padding($padding = null)- Setpoption.color($color = null)- Setfcoption.background($color = null)- Setbcoption.quietZone($size = null)- Setwqoption.density($density = null)- Setmdoption.
Generate QR methods
render_image()- Return generated GD resource.raw()- Return raw PNG image data.base64()- Return bse64 encoded PNG image data.