endroid/qr-code
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
bacon/bacon-qr-code | 2.0.8 | 93.9 kB | BSD-2-Clause | prod |
Endroid/qr-code is a popular PHP library aimed at generating QR (Quick Response) codes instantly. It leverages the power of bacon/bacon-qr-code
to generate the matrix and khanamiryan/qrcode-detector-decoder
to validate generated QR codes. This library also offers Twig extensions, generation routes, a factory, and a Symfony bundle for easy installation and configuration. What's more, it provides different writers to generate the QR code as PNG, SVG, EPS, or in binary format.
To use Endroid/qr-code, firstly, ensure that you have installed it via Composer and that you have enabled and configured the GD extension if images are being generated. The installation command is composer require endroid/qr-code
. After installation, you can generate QR codes using the builder provided by the library. Here is a sample snippet:
<?php
use Endroid\QrCode\Builder\Builder;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\Label\LabelAlignment;
use Endroid\QrCode\Label\Font\NotoSans;
use Endroid\QrCode\RoundBlockSizeMode;
use Endroid\QrCode\Writer\PngWriter;
$result = Builder::create()
->writer(new PngWriter())
...
->data('QR Code Content')
...
->build();
?>
The generated QR code can be output directly, saved to a file or used in an <img>
tag via a data URI as shown below:
<?php
...
header('Content-Type: '.$result->getMimeType());
echo $result->getString();
// Or save to a file
$result->saveToFile('path_to_save/qrcode.png');
// Or get dataUri
$dataUri = $result->getDataUri();
?>
The documentation for Endroid/qr-code can be found primarily in the README file on the package's GitHub page. You can also find more details about multiple configurations, integration with Symfony and Twig function usage in the documentation for Endroid QR Code Bundle if you're using Symfony. Additionally, specific usage details about writer options, round block size mode, QR code validity, and more, are copiously given in the same README.