• Stars
    star
    278
  • Rank 148,454 (Top 3 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bundle for generating QR codes in Symfony

QR Code Bundle

By endroid

Latest Stable Version Build Status Total Downloads Monthly Downloads License

This Symfony bundle lets you generate QR Codes using the endroid/qr-code library. It provides the following features:

  • Configure your defaults (like image size, default writer etc.)
  • Support for multiple configurations and injection via aliases
  • Generate QR codes for defined configurations via URL like /qr-code//Hello
  • Generate QR codes or URLs directly from Twig using dedicated functions

Installation

Use Composer to install the library. Also make sure you have enabled and configured the GD extension if you want to generate images.

composer require endroid/qr-code-bundle

When you use Symfony, the installer makes sure that services are automatically wired. If this is not the case you can find the configuration files in the .install/symfony folder.

If you don't want the installer to create the auto-configuration files, it can be disabled as described here.

Configuration

The bundle makes use of builders to create QR codes. The default parameters applied by the builder can optionally be overridden via the configuration. and multiple configurations (thus builders) can be defined.

endroid_qr_code:
    default:
        writer: Endroid\QrCode\Writer\PngWriter
        data: 'This is customized QR code'
        # Label is not implemented for SvgWriter
        labelText: 'This is the label'
        labelFontPath: '%kernel.project_dir%/vendor/endroid/qr-code/assets/noto_sans.otf'
        labelFontSize: 20
        labelAlignment: 'center'
    custom:
        writer: Endroid\QrCode\Writer\SvgWriter
        writerOptions:
            exclude_xml_declaration: true # default: false
        data: 'This is customized QR code'
        size: 300
        encoding: 'UTF-8'
        errorCorrectionLevel: 'low' # 'low', 'medium', 'quartile', or 'high'
        roundBlockSizeMode: 'margin'
        logoPath: '%kernel.project_dir%/vendor/endroid/qr-code/tests/assets/symfony.png'
        logoResizeToWidth: 150
        logoPunchoutBackground: true
        validateResult: false

Using builders

Each configuration results in a builder which can be injected in your classes. For instance the custom builder from the example above can be injected like this and you can override the default configuration as follows.

use Endroid\QrCode\Builder\BuilderInterface;

public function __construct(BuilderInterface $customQrCodeBuilder)
{
    $result = $customQrCodeBuilder
        ->size(400)
        ->margin(20)
        ->build();
}

QR Code Response

The bundle also provides a response object to ease rendering of the resulting image by automatically saving to contents and setting the correct content type.

use Endroid\QrCodeBundle\Response\QrCodeResponse;

$response = new QrCodeResponse($result);

Generate via URL

The bundle provides a controller that allows you to generate QR codes simply by opening an URL like /qr-code/{builder}/{data}. You can configure the prefix in your routing file and pass any of the existing options via query string.

Generate via Twig

The bundle provides a Twig extension for generating a QR code URL, path or data URI. You can use the second argument to specify the builder to use.

<img src="{{ qr_code_path('My QR Code') }}" />
<img src="{{ qr_code_url('My QR Code') }}" />
<img src="{{ qr_code_data_uri('My QR Code') }}" />

{# You can specify the builder via the second parameter #}
<img src="{{ qr_code_data_uri('My QR Code', 'custom') }}" />

Versioning

Version numbers follow the MAJOR.MINOR.PATCH scheme. Backwards compatibility breaking changes will be kept to a minimum but be aware that these can occur. Lock your dependencies for production and test your code when upgrading.

License

This source code is subject to the MIT license bundled in the file LICENSE.

More Repositories

1

qr-code

QR Code Generator
PHP
4,354
star
2

installer

Composer plugin for installing package configuration files
PHP
140
star
3

pdf

Library for easy PDF generation using wkhtmltopdf and Snappy
PHP
31
star
4

simple-spreadsheet

Library to simplify spreadsheet imports and exports
PHP
13
star
5

asset

Abstraction layer for providing contents from different sources
PHP
9
star
6

image-placeholder

Easy integration of image placeholders in your project
PHP
8
star
7

embed

Twig extension for embedding external resources
PHP
8
star
8

flusher

Auto optimizing entity manager flusher
PHP
6
star
9

property-access

Combines Symfony Property Access and Expression Language
PHP
6
star
10

calendar

Calendar reader / writer
PHP
6
star
11

sudoku

Sudoku solver
PHP
4
star
12

docker-php

Docker PHP image
Dockerfile
3
star
13

docker-rust

Docker Rust image
Dockerfile
2
star
14

data-sanitize

Library for cleaning data, removing duplicates etc.
PHP
2
star
15

teleporter

Copies files from one location to another while filtering the file contents based on specified modules
PHP
2
star
16

soccer-data

PHP
2
star
17

quality

Provides a default and up to date test configuration for libraries
Shell
2
star
18

docker-node

Docker node image
Dockerfile
1
star
19

application

TypeScript
1
star
20

docker-python

Docker Python image
Dockerfile
1
star
21

soccer-calendar

PHP
1
star
22

soccer-calendar-bundle

Generates soccer calendars for teams in configured competitions
PHP
1
star
23

composer-message

Show an error, warning or info message on composer install
PHP
1
star
24

tile

Tile Generator
PHP
1
star
25

data-sanitize-demo-bundle

Demo bundle for cleaning data, removing duplicates etc.
PHP
1
star