Kirby CMS Panel Field and Page-Method rendering a QR Code.
This plugin is free but if you use it in a commercial project please consider to make a donation 🍻.
Notes:
- This plugin uses the endroid/QrCode lib v1.9.3.
- This plugin does not cache the image but recreate it on every request and will save it to the
/thumbs
folder (kirby()->roots()->thumbs()
).
- Kirby 2.3+
kirby plugin:install bnomei/kirby-qrcode
$ git submodule add https://github.com/bnomei/kirby-qrcode.git site/plugins/kirby-qrcode
- Download the contents of this repository as ZIP-file.
- Rename the extracted folder to
kirby-qrcode
and copy it into thesite/plugins/
directory in your Kirby project.
Add a kirby panel field to your blueprint to show a qrcode of the kirby $page->url()
within the panel. This plugin uses a global field definition to cut some corners.
Default paramters of QR code lib will be used to render the image or the parameters set in your config.php
.
#fieldname: fieldtype
qrcode: qrcode
The plugin also adds a $page->qrcode()
function which returns an image as Media object to use in templates etc.
You can use the default values, override them or set your own parameters on-the-fly using an associative array. Missing parameters will fallback to defaults of lib.
// DEFAULTS
$qrcodeDefault = $page->qrcode(); // Kirby Toolkit Media Object
// CUSTOM
$allCustomParameters = [
'Text' => $page->url(), // plugin default
'Size' => 300,
'Padding' => 10,
'ErrorCorrection' => 'high',
'ForegroundColor' => ['r' => 0, 'g' => 0, 'b' => 255, 'a' => 0],
'BackgroundColor' => ['r' => 255, 'g' => 255, 'b' => 255, 'a' =>0],
'Label' => 'You take the blue pill',
'LabelFontSize' => 16,
'ImageType' => Endroid\QrCode\QrCode::IMAGE_TYPE_PNG, // lib default
'Filename' => $page->slug().'-qrcode', // plugin default
];
// override defaults. this can be done in config.php as well.
c::set('plugin.qrcode', $allCustomParameters);
$qrcodeCustom = $page->qrcode(); // using new defaults now
// or use them on-the-fly
$qrcodeCustom = $page->qrcode([
'Label' => 'You take the red pill',
'ForegroundColor' => ['r' => 255, 'g' => 0, 'b' => 0, 'a' => 0],
'ImageType' => Endroid\QrCode\QrCode::IMAGE_TYPE_JPEG,
]);
// then use media object to get brick and echo the image
// https://github.com/getkirby/toolkit/blob/master/lib/media.php#L539
echo $qrcodeCustom->html();
This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.
It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.