Put together a silly little php script to build an SVG QR code dynamically. This started a while ago as a quick way to get a printable QR code for each pinball machine that would shoot you to an issue report form with the name of the game prefilled.
I previously generated a bunch of PNGs with qrencode(1) and used php to list them on the web but that requires ssh access to generate new ones.
For some reason the old one is a fish shell script (I use it as my interactive shell but don’t usually write scripts with it).
for pin in $(cat coinslot.txt)
echo https://tcpinball.org/report-issue/tcs/\?game=$(string escape --style=url $pin) \
| qrencode -t png -o qr/tcs/$(string escape --style=url $pin).png
end
for pin in $(cat rightbrain.txt)
echo https://tcpinball.org/report-issue/rbb/\?game=$(string escape --style=url $pin) \
| qrencode -t png -o qr/rbb/$(string escape --style=url $pin).png
endSource here: qr.fish.
Here’s the new script. It uses chillerlan/php-qrcode to build the QR code.
<?php
declare(strict_types=1);
use chillerlan\QRCode\{QRCode, QROptions};
use chillerlan\QRCode\Output\QRMarkupSVG;
require_once 'vendor/autoload.php';
if (empty($_GET["q"])) {
echo '<form method=GET><input name=q /></form>';
} else {
$options = new QROptions();
$options->outputInterface = QRMarkupSVG::class;
$options->outputBase64 = false;
if (PHP_SAPI !== 'cli') {
header('Content-type: image/svg+xml');
header('Content-Disposition: filename=qr.svg');
}
echo (new QRCode($options))->render(html_entity_decode($_GET["q"]));
}
die();Example image from this script:
Leave a Reply