PHPackages                             bnomei/kirby3-qrcode - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. bnomei/kirby3-qrcode

AbandonedArchivedKirby-plugin[PDF &amp; Document Generation](/categories/documents)

bnomei/kirby3-qrcode
====================

Generate QRCodes. The included Panel-Field will show the QRCode and trigger download on click.

2.2.0(2y ago)123.0k3[2 issues](https://github.com/bnomei/kirby3-qrcode/issues)[3 PRs](https://github.com/bnomei/kirby3-qrcode/pulls)MITPHPPHP &gt;=8.0

Since Oct 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/bnomei/kirby3-qrcode)[ Packagist](https://packagist.org/packages/bnomei/kirby3-qrcode)[ RSS](/packages/bnomei-kirby3-qrcode/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (5)Versions (20)Used By (0)

Kirby QRCode
============

[](#kirby-qrcode)

[![Release](https://camo.githubusercontent.com/a44a0c7dbdf9c0dffffb526c27ecfe83e5da21c9649420e05ea15d8e32bf2609/68747470733a2f2f666c61742e62616467656e2e6e65742f7061636b61676973742f762f626e6f6d65692f6b69726279332d7172636f64653f636f6c6f723d616538316666)](https://camo.githubusercontent.com/a44a0c7dbdf9c0dffffb526c27ecfe83e5da21c9649420e05ea15d8e32bf2609/68747470733a2f2f666c61742e62616467656e2e6e65742f7061636b61676973742f762f626e6f6d65692f6b69726279332d7172636f64653f636f6c6f723d616538316666)[![Downloads](https://camo.githubusercontent.com/2b4bc83b8b58b9e9bb4c2fb6b4694baf23dd64091621856ee156d9f0219a2f58/68747470733a2f2f666c61742e62616467656e2e6e65742f7061636b61676973742f64742f626e6f6d65692f6b69726279332d7172636f64653f636f6c6f723d323732383232)](https://camo.githubusercontent.com/2b4bc83b8b58b9e9bb4c2fb6b4694baf23dd64091621856ee156d9f0219a2f58/68747470733a2f2f666c61742e62616467656e2e6e65742f7061636b61676973742f64742f626e6f6d65692f6b69726279332d7172636f64653f636f6c6f723d323732383232)[![Build Status](https://camo.githubusercontent.com/9b814d28dbeccdb64fada8cbbafd4307b1c8433c02184c5c1b579a39e1b1fc13/68747470733a2f2f666c61742e62616467656e2e6e65742f7472617669732f626e6f6d65692f6b69726279332d7172636f6465)](https://travis-ci.com/bnomei/kirby3-qrcode)[![Coverage Status](https://camo.githubusercontent.com/9d791060d72adc7bd5ec62b8ec3d4bc9da1edad38cf9c9c52be8341e9d2bf45a/68747470733a2f2f666c61742e62616467656e2e6e65742f636f766572616c6c732f632f6769746875622f626e6f6d65692f6b69726279332d7172636f6465)](https://coveralls.io/github/bnomei/kirby3-qrcode)[![Maintainability](https://camo.githubusercontent.com/b138809ae9b06a28bbdd666a85abfbbf40dd28987fdce5daced594d01fc1c330/68747470733a2f2f666c61742e62616467656e2e6e65742f636f6465636c696d6174652f6d61696e7461696e6162696c6974792f626e6f6d65692f6b69726279332d7172636f6465)](https://codeclimate.com/github/bnomei/kirby3-qrcode)[![Twitter](https://camo.githubusercontent.com/b90e4b58a887e8ad09ec267628b75199a48522a9e01e88b129e5d2d730dffe50/68747470733a2f2f666c61742e62616467656e2e6e65742f62616467652f747769747465722f626e6f6d65693f636f6c6f723d363664396566)](https://twitter.com/bnomei)

Generate QRCodes easily. The included Panel-Field will show the QRCode and trigger download on click.

Installation
------------

[](#installation)

- unzip [master.zip](https://github.com/bnomei/kirby3-qrcode/archive/master.zip) as folder `site/plugins/kirby3-qrcode` or
- `git submodule add https://github.com/bnomei/kirby3-qrcode.git site/plugins/kirby3-qrcode` or
- `composer require bnomei/kirby3-qrcode`

Usecase
-------

[](#usecase)

### Raw PHP

[](#raw-php)

```
$qrcodeObject = new \Bnomei\QRCode([
    'Text' => 'https://github.com/bnomei/kirby3-qrcode',
]);
echo $qrcodeObject->html('qrcode-plugin.png');
```

### Page Method

[](#page-method)

**site/templates/default.php**

```
// base64 encoded png image tag
// with $page->url() as Text
echo $page->qrcode()->html(
    $page->slug() . '.png' // image format detected from extension
);
```

### Save as File in Page Object

[](#save-as-file-in-page-object)

When saving you can in addtion to the filename provide additional content data for the file or force an overwrite (which will change UUID and media hash) with additional function params. The logic will use the currently logged-in user or impersonate as `kirby` to create the file.

**site/templates/default.php**

```
$qrcodeFilename = $page->slug() . '.png';
$file = $page->file($qrcodeFilename);

if (!$file) {
    // short version
    $file = $page->qrcode()->save(
        $qrcodeFilename
    );

    // with all params
    $file = $page->qrcode()->save(
        $qrcodeFilename,
        'myfiletemplate', // or null
        [/* my content data array */],
        true // force overwrite
    );
}

echo $file; // outputs a img tag
```

> Why not overwrite file by default? Let's assume you want to send the qrcode by email. Then you do not want to overwrite later because that would change the media hash and break the URL to the image send within the email.

> Could I not embed the qrcode inline using base-64 encoding? Technically yes, but almost no email clients would render it.

### Trigger download

[](#trigger-download)

**site/templates/default.qr.php**

```
$page->qrcode()->download(
    $page->slug() . '.png'
);
```

### Further customization of the generated image

[](#further-customization-of-the-generated-image)

[Advanced options](https://github.com/endroid/qr-code#usage-using-the-builder) can be set.

```
echo $page->qrcode([
    'margin' => 10,
    'encoding' => 'UTF-8',
    'foregroundColor' => new \Endroid\QrCode\Color\Color(0, 0, 0),
    'backgroundColor' => new \Endroid\QrCode\Color\Color(255, 255, 255),
    'labelText' => 'Scan the code',
    'logoPath' => __DIR__.'/../assets/images/getkirby.png',
    'size' => 200,
])->html(
    $page->slug() . '.png'
);
```

> TIP: You could move that options array for frontend rendering into a config value or reuse the option('bnomei.qrcode.field') which defines the look inside the panel.

Panel Field: Url of Page/File as QRCode
---------------------------------------

[](#panel-field-url-of-pagefile-as-qrcode)

Add the field to a blueprint. This will show the QRCode as PNG image and will trigger the download of the file on click.

**site/blueprints/default.yml**

```
fields:
  # current page
  qrcode: qrcode

  qrcode2:
    type: qrcode
    title: Text below image

  # title with query
  qrcode3:
    type: qrcode
    title: "{{ page.title }}"

  # custom url
  qrcode4:
    type: qrcode
    title: Panel Url of {{ page.title }}
    url: "{{ page.panel.url }}"

  # custom url and custom filename with |
  qrcode4:
    type: qrcode
    title: Issue 7
    url: "https://github.com/bnomei/kirby3-qrcode/issues/7|Issue 7"
```

You can define the options how the qrcode field shows the image **inside the panel** in your config file. Example:

**site/config/config.php**

```
