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

0.0.1 2025-04-25 17:41 UTC

This package is auto-updated.

Last update: 2025-05-14 08:51:06 UTC


README

English | 中文

Latest Version License

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.