88[ ![ Monthly Downloads] ( http://img.shields.io/packagist/dm/endroid/qr-code-bundle.svg )] ( https://packagist.org/packages/endroid/qr-code-bundle )
99[ ![ License] ( http://img.shields.io/packagist/l/endroid/qr-code-bundle.svg )] ( https://packagist.org/packages/endroid/qr-code-bundle )
1010
11- This Symfony bundle lets you generate QR Codes using the [ endroid/qr-code] ( https://github.com/endroid/QrCode )
11+ This Symfony bundle lets you generate QR Codes using the [ endroid/qr-code] ( https://github.com/endroid/qr-code )
1212library. It provides the following features:
1313
1414* Configure your defaults (like image size, default writer etc.)
@@ -25,48 +25,59 @@ Use [Composer](https://getcomposer.org/) to install the library. Also make sure
2525composer require endroid/qr-code-bundle
2626```
2727
28- When you use Symfony, the [ installer] ( https://github.com/endroid/installer )
29- makes sure that services are automatically wired. If this is not the case you
30- can find the configuration files in the ` .install/symfony ` folder.
28+ ### Route Configuration
3129
32- If you don't want the installer to create the auto-configuration files, it can
33- be disabled as described [ here] ( https://github.com/endroid/installer#configuration ) .
30+ By default the bundle registers a controller that generates QR codes via the URL
31+ ` /qr-code/{builder}/{data} ` . If you only use QR codes programmatically or via Twig
32+ and don't need the route, you can disable it. You can also set a custom prefix.
3433
35- ## Configuration
34+ ``` yaml
35+ endroid_qr_code :
36+ route_enabled : true
37+ route_prefix : ' /my-custom-prefix'
38+ ` ` `
39+
40+ This makes the route available at ` /my-custom-prefix/{builder}/{data}`.
41+
42+ # # Builder Configuration
3643
3744The bundle makes use of builders to create QR codes. The default parameters
38- applied by the builder can optionally be overridden via the configuration. and
45+ applied by the builder can optionally be overridden via the configuration. And
3946multiple configurations (thus builders) can be defined.
4047
48+ Each entry under `builders` defines a named builder with its own defaults.
49+ When no builders are configured the bundle registers a single `default` builder.
50+
4151` ` ` yaml
4252endroid_qr_code:
43- default :
44- writer : Endroid\QrCode\Writer\PngWriter
45- data : ' This is customized QR code'
46- logo_path : ' %kernel.project_dir%/vendor/endroid/qr-code/tests/assets/symfony.png'
47- logo_resize_to_width : 150
48- logo_punchout_background : true # only supported by PngWriter
49- label_text : ' This is the label'
50- label_font_path : ' %kernel.project_dir%/vendor/endroid/qr-code/assets/noto_sans.otf'
51- label_font_size : 20
52- label_alignment : ' center'
53- custom :
54- writer : Endroid\QrCode\Writer\SvgWriter
55- writer_options :
56- exclude_xml_declaration : true # default: false
57- data : ' This is customized QR code'
58- size : 300
59- encoding : ' UTF-8'
60- error_correction_level : ' low' # 'low', 'medium', 'quartile', or 'high'
61- round_block_size_mode : ' margin'
62- validate_result : false
53+ builders:
54+ default:
55+ writer: Endroid\Q rCode\W riter\P ngWriter
56+ data: 'This is customized QR code'
57+ logo_path: '%kernel.project_dir%/vendor/endroid/qr-code/tests/assets/symfony.png'
58+ logo_resize_to_width: 150
59+ logo_punchout_background: true # only supported by PngWriter
60+ label_text: 'This is the label'
61+ label_font_path: '%kernel.project_dir%/vendor/endroid/qr-code/assets/noto_sans.otf'
62+ label_font_size: 20
63+ label_alignment: 'center'
64+ custom:
65+ writer: Endroid\Q rCode\W riter\S vgWriter
66+ writer_options:
67+ exclude_xml_declaration: true # default: false
68+ data: 'This is customized QR code'
69+ size: 300
70+ encoding: 'UTF-8'
71+ error_correction_level: 'low' # 'low', 'medium', 'quartile', or 'high'
72+ round_block_size_mode: 'margin'
73+ validate_result: false
6374` ` `
6475
65- ## Using builders
76+ # # Using Named Builders
6677
67- Each configuration results in a builder which can be injected in your classes.
68- For instance the custom builder from the example above can be injected like this
69- and you can override the default configuration as follows.
78+ Each builder is available for injection using its name suffixed with
79+ ` QrCodeBuilder ` . For example the ` custom` builder above can be injected as
80+ `$customQrCodeBuilder`. You can override the configured defaults at build time :
7081
7182` ` ` php
7283use Endroid\Q rCode\B uilder\B uilderInterface;
@@ -91,13 +102,7 @@ use Endroid\QrCodeBundle\Response\QrCodeResponse;
91102$response = new QrCodeResponse($result);
92103` ` `
93104
94- ## Generate via URL
95-
96- The bundle provides a controller that allows you to generate QR codes simply
97- by opening an URL like /qr-code/{builder}/{data}. You can configure the prefix
98- in your routing file and pass any of the existing options via query string.
99-
100- ## Generate via Twig
105+ # # Twig Extension
101106
102107The bundle provides a Twig extension for generating a QR code URL, path or data
103108URI. You can use the second argument to specify the builder to use.
@@ -114,6 +119,8 @@ URI. You can use the second argument to specify the builder to use.
114119{% set qrCode = qr_code_result('My QR Code') %}
115120<img src="{{ qrCode.dataUri }}" width="{{ qrCode.matrix.outerSize }}" />
116121` ` `
122+
123+ Please note that some Twig functions need the route to be enabled to function.
117124
118125# # Versioning
119126
0 commit comments