49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\QrCode\Services;
|
|
|
|
use chillerlan\QRCode\QRCode;
|
|
use chillerlan\QRCode\QROptions;
|
|
use chillerlan\QRCode\Output\QRMarkupSVG;
|
|
use chillerlan\QRCode\Output\QRGdImagePNG;
|
|
|
|
class QrRenderer
|
|
{
|
|
public function toSvg(string $data, array $style): string
|
|
{
|
|
$options = new QROptions([
|
|
'outputInterface' => QRMarkupSVG::class,
|
|
'outputBase64' => false,
|
|
]);
|
|
|
|
return (new QRCode($options))->render($data);
|
|
}
|
|
|
|
public function toPngBase64(string $data, array $style): string
|
|
{
|
|
$options = new QROptions([
|
|
'outputInterface' => QRGdImagePNG::class,
|
|
'outputBase64' => true,
|
|
'scale' => 10,
|
|
]);
|
|
|
|
return (new QRCode($options))->render($data);
|
|
}
|
|
|
|
public function buildPayload(string $type, array $data): string
|
|
{
|
|
return match ($type) {
|
|
'url' => $data['url'],
|
|
'text' => $data['text'],
|
|
'wifi' => "WIFI:T:{$data['encryption']};S:{$data['ssid']};P:{$data['password']};;",
|
|
'vcard' => $this->buildVcard($data),
|
|
default => $data['url'] ?? '',
|
|
};
|
|
}
|
|
|
|
private function buildVcard(array $d): string
|
|
{
|
|
return "BEGIN:VCARD\nVERSION:3.0\nFN:{$d['name']}\nEMAIL:{$d['email']}\nTEL:{$d['phone']}\nEND:VCARD";
|
|
}
|
|
}
|