Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save abenevaut/49afd6ae4534395a80e68189a3c829ef to your computer and use it in GitHub Desktop.
Save abenevaut/49afd6ae4534395a80e68189a3c829ef to your computer and use it in GitHub Desktop.
{
"name": "abenevaut/flash",
"description": "QRCode generator",
"type": "project",
"license": "proprietary",
"autoload": {
"psr-4": {
"abenevaut\\Flash\\": "src/"
}
},
"authors": [
{
"name": "Antoine Benevaut",
"email": "[email protected]"
}
],
"require": {
"ext-imagick": "*",
"simplesoftwareio/simple-qrcode": "^4.2",
"illuminate/validation": "^11",
"illuminate/translation": "^11",
"bref/bref": "^2.1",
"bref/extra-php-extensions": "^1.4"
},
"minimum-stability": "stable"
}
<?php declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use Illuminate\Translation\{ArrayLoader, Translator};
use Illuminate\Validation\Factory;
use SimpleSoftwareIO\QrCode\Generator;
return function ($event) {
$validationTranslations = require __DIR__ . '/vendor/illuminate/translation/lang/en/validation.php';
$translations = (new ArrayLoader())->addMessages('en', 'validation', $validationTranslations);
$validator = new Factory(new Translator($translations, 'en'));
$validator
->make($event, [
'correction' => 'required|string|in:L,M,Q,H',
'format' => 'required|string|in:png,svg,eps',
'size' => 'required|integer',
'text' => 'required|string',
'image' => 'url',
])
->validate();
unset($validator);
$qrGenerator = new Generator();
$qrCode = $qrGenerator
->format($event['format'])
->errorCorrection($event['correction'])
->size($event['size']);
unset($qrGenerator);
if (isset($event['image'])) {
$qrCode->merge($event['image'], .2, true);
}
return base64_encode($qrCode->generate($event['text'])->toHtml());
};
<?php declare(strict_types=1);
$event = [
"correction" => "L",
"format" => "png",
"size" => 100,
"text" => "1234",
];
$qrCodeFunction = require('./index.php');
$base64QrCode = call_user_func($qrCodeFunction, $event);
echo $base64QrCode;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment