PHP code example of yoosuf / qr
1. Go to this page and download the library: Download yoosuf/qr library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yoosuf / qr example snippets
use Yoosuf\Qr\Facades\Qr;
$svg = Qr::render('SO-1001')->contents;
$dataUri = Qr::dataUri('SO-1001', 'svg', [
'profile' => 'brand',
]);
$storedPath = Qr::save('qr/so-1001.svg', 'SO-1001');
use Yoosuf\Qr\Facades\Qr;
use Yoosuf\Qr\Support\QrPayload;
$wifi = QrPayload::wifi('Office-5G', 'super-secret-password', 'WPA2', false);
$vcard = QrPayload::vcard([
'first_name' => 'Yoosuf',
'last_name' => 'A',
'organization' => 'Nord',
'title' => 'Engineer',
'phone' => '+9607000000',
'email' => '[email protected] ',
'url' => 'https://example.com',
]);
$svgWifi = Qr::render($wifi)->contents;
$svgContact = Qr::render($vcard)->contents;
// Array payload syntax also works
$sms = Qr::render([
'type' => 'sms',
'number' => '+9607000000',
'message' => 'Hello from QR',
]);
qr()->extendPayload('upi', function (array $payload): string {
$vpa = $payload['vpa'] ?? '';
$name = $payload['name'] ?? '';
return 'upi://pay?pa='.rawurlencode((string) $vpa).'&pn='.rawurlencode((string) $name);
});
qr()->extendModule('hex', function (string $name, array $options) {
return \BaconQrCode\Renderer\Module\SquareModule::instance();
});
// config/qr.php
'cache' => [
'enabled' => true,
'store' => 'redis',
'ttl' => 3600,
'prefix' => 'qr',
],
bash
php artisan vendor:publish --tag=qr-config
bash
php artisan qr:generate "SO-1001" --driver=svg --path=qr/so-1001.svg
bash
php artisan qr:generate "SO-1001" \
--driver=svg \
--path=qr/so-1001-brand.svg \
--option=profile=brand \
--option=size=512 \
--option=foreground_gradient.type=diagonal \
--option=foreground_gradient.start_color=#0f172a \
--option=foreground_gradient.end_color=#0ea5e9