Giter Club home page Giter Club logo

qr-code-bundle's Introduction

QR Code Bundle

By endroid

Latest Stable Version Build Status Total Downloads Monthly Downloads License

This Symfony 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.)
  • Generate QR codes quickly from anywhere via the factory service
  • Generate QR codes directly by typing an URL like /qr-code/<text>.png?size=300
  • Generate QR codes or URLs directly from Twig using dedicated functions

Installation

Use Composer to install the library.

$ 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.

Configuration

The bundle makes use of a factory to create QR codes. The default parameters applied by the factory can optionally be overridden via the configuration.

endroid_qr_code:
    writer: 'svg'
    size: 300
    margin: 10
    foreground_color: { r: 0, g: 0, b: 0 }
    background_color: { r: 255, g: 255, b: 255 }
    error_correction_level: low # low, medium, quartile or high
    encoding: UTF-8
    label: Scan the code
    label_font_size: 20
    label_alignment: left # left, center or right
    label_margin: { b: 20 }
    logo_path: '%kernel.root_dir%/../vendor/endroid/qr-code/assets/images/symfony.png'
    logo_width: 150
    logo_height: 200
    validate_result: false # checks if the result is readable
    writer_options:
        exclude_xml_declaration: true

Generate via factory

Now you can retrieve the factory from the service container and create a QR code. You can also pass options to override defaults set by your configuration.

$qrCode = $qrCodeFactory->create('QR Code', ['size' => 200]);

QR Code Response

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

$response = new QrCodeResponse($qrCode);

Generate via URL

The bundle provides a controller that allows you to generate QR codes simply by opening an URL like /qr-code/<text>.png?size=300. 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 of any of these functions to override any defaults defined by the bundle or set via your configuration.

<img src="{{ qr_code_path(message) }}" />
<img src="{{ qr_code_url(message, { writer: 'eps' }) }}" />
<img src="{{ qr_code_data_uri(message, { writer: 'svg', size: 150 }) }}" />

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.

qr-code-bundle's People

Contributors

endroid avatar qdequippe avatar calvera avatar curry684 avatar philetaylor avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.