tourze / bacon-qr-code-bundle
Symfony Bundle for bacon/bacon-qr-code
Installs: 651
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.1
- bacon/bacon-qr-code: ^3.0
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-foundation: ^6.4
- symfony/http-kernel: ^6.4
- symfony/routing: ^6.4
- symfony/yaml: ^6.4 || ^7.1
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-05-14 08:51:06 UTC
README
A Symfony bundle for bacon/bacon-qr-code library that provides QR code generation capabilities in your Symfony application.
Features
- Easy integration with Symfony applications
- Multiple output formats support (PNG, SVG, EPS)
- Customizable QR code size and margin
- Simple URL generation for QR codes
- Automatic detection of available image libraries (GD, Imagick)
Installation
composer require tourze/bacon-qr-code-bundle
Register the bundle in your config/bundles.php
:
<?php return [ // ... BaconQrCodeBundle\BaconQrCodeBundle::class => ['all' => true], ];
Import routes in your config/routes.yaml
:
bacon_qr_code: resource: '@BaconQrCodeBundle/Resources/config/routes.yaml'
Quick Start
Generate QR Code URL
<?php use BaconQrCodeBundle\Service\QrcodeService; class YourController { public function example(QrcodeService $qrcodeService) { // Generate URL for QR code image $qrCodeUrl = $qrcodeService->getImageUrl('https://example.com'); // Use this URL in your templates return $this->render('your_template.html.twig', [ 'qrCodeUrl' => $qrCodeUrl, ]); } }
Display QR Code in Twig Template
<img src="{{ qrCodeUrl }}" alt="QR Code"> {# With custom parameters #} <img src="{{ path('qr_code_generate', { 'data': 'https://example.com', 'size': 400, 'margin': 0, 'format': 'svg' }) }}" alt="QR Code">
Direct QR Code Generation
<?php use BaconQrCodeBundle\Service\QrcodeService; use Symfony\Component\HttpFoundation\Response; class YourController { public function generateQrCode(QrcodeService $qrcodeService): Response { $options = [ 'size' => 300, // Size in pixels 'margin' => 10, // Margin in pixels 'format' => 'png', // Format: 'png', 'svg', 'eps' ]; // Return Response object with QR code content return $qrcodeService->generateQrCode('https://example.com', $options); } }
Available Options
When generating QR codes, you can customize the following options:
Option | Description | Default Value |
---|---|---|
size |
Size of the QR code in pixels | 300 |
margin |
Margin around the QR code in pixels | 10 |
format |
Output format ('png', 'svg', 'eps') | 'png' if GD or Imagick is available, otherwise 'svg' |
License
The MIT License (MIT). Please see License File for more information.