QR Code Styling CLI

npm license npm scope

Effortlessly generate customised QR codes from the command line

Datasets and templates

When using the --template-data option to specify a JSON dataset, the data can be merged into the configuration using Handlebars syntax to generate parametrised QR codes. As shown in the example dataset below, an entry can have a special "$matrix" field in the form of key: [values]; such entries will be expanded to all possible combinations of matrix values (in this case, one entry with "color": "#fedcba" and one with "color": "#abcdef").

[
    {
        "id": "123",
        "name": "Bob",
        "image": "https://example.com/profile/123.png",
        "$matrix": {
            "color": [
                "#fedcba",
                "#abcdef"
            ]
        }
    },
    {
        "id": "456",
        "name": "Conny",
        "image": "https://example.com/profile/456.png",
        "color": "#bfffca"
    }
]

Each entry’s fields can then be merged into the configuration file as shown below, where we generate a personalised QR code for each employee in the dataset using their company profile image and id for the QR code, and their name and colour to add a custom border. Since some employees receive multiple QR codes with different-coloured borders, "outputFilename": "qr-{{ hash id color }}" property is added to the configuration to ensure unique filenames.

{
    "$schema": "./node_modules/@liquid-js/qr-code-styling-cli/lib/schema.json",
    "data": "https://www.example.com/profile?id={{ urlEscape id }}",
    "image": "{{ image }}",
    "imageOptions": {
        "mode": "center",
        "imageSize": 0.9,
        "margin": 1
    },
    "shape": "circle",
    "backgroundOptions": {
        "margin": 3,
        "round": 1,
        "color": "#fff"
    },
    "plugins": [
        {
            "plugin": "@liquid-js/qr-code-styling/border-plugin",
            "round": 1,
            "size": 0.15,
            "color": "{{ color }}",
            "proportional": true,
            "text": {
                "color": "#000",
                "size": 0.7,
                "top": {
                    "content": "Hi! I'm {{ name }}"
                },
                "bottom": {
                    "content": "See my company profile"
                }
            }
        }
    ],
    "outputFilename": "qr-{{ hash id color }}"
}