2017 © Pedro Peláez
 

symfony-bundle qr-code-bundle

Symfony2Barcode Generator Bundle with Twig function extension

image

yellowskies/qr-code-bundle

Symfony2Barcode Generator Bundle with Twig function extension

  • Sunday, July 29, 2018
  • by AntoineTesson
  • Repository
  • 2 Watchers
  • 14 Stars
  • 25,626 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 10 Versions
  • 38 % Grown

The README.md

YellowskiesQRcodeBundle

WORKS WITH PHP >= 7.1 AND SYMFONY 4/ 5 / 6 AND Twig 2.x, (*1)

Latest Stable Version, (*2)

YellowskiesQRcodeBundle is a Symfony4/5/6 Barcode Generator Bundle., (*3)

Features:, (*4)

  1. Support 3 two-dimensional (2D) and 30 one-dimensional (1D) Barcode types
  2. Three output formats: HTML, PNG and SVG canvas
  3. Twig integration: you can simply use a extensional function of Twig in the template to generate Barcode
  4. Core of this bundle from this project tc-lib-barcode

Installation

Add YellowskiesQRcodeBundle by running the command:, (*5)

$ php composer.phar require yellowskies/qr-code-bundle 

Or, add YellowskiesQRcodeBundle to your composer.json, then execute php composer.phar update, (*6)


"require": { "yellowskies/qr-code-bundle": "1.2.10" }

Composer will install the bundle to your project's vendor/yellowskies directory., (*7)

Then, Enable the bundle in the kernel:, (*8)

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Skies\QRcodeBundle\SkiesQRcodeBundle(),
    );
}

Generate options

To generate one barcode, you have 5 options can be configured., (*9)

option type required allowed values description
code string required what you want encoded
type string required Supported Types type of barcode
format string required html, svg, png output format
width integer optional width of unit
height integer optional height of unit
color string for html, svg / array for png optional HTML Color Names / array(R, G, B) barcode color

Default width and height for 2D barcode are 5, 5, for 1D are 2, 30. Default color for html, svg is black, for png is array(0, 0, 0), (*10)

Usage by service

The bundle registers one service: skies_barcode.generator which will allows you to generate barcode:, (*11)

  • output html
$options = array(
    'code'   => 'string to encode',
    'type'   => 'c128',
    'format' => 'html',
);

$barcode =
    $this->get('skies_barcode.generator')->generate($options);

return new Response($barcode);
  • output svg
$options = array(
    'code'   => 'string to encode',
    'type'   => 'qrcode',
    'format' => 'svg',
    'width'  => 10,
    'height' => 10,
    'color'  => 'green',
);

$barcode =
    $this->get('skies_barcode.generator')->generate($options);

return new Response($barcode);
  • output png
$options = array(
    'code'   => 'string to encode',
    'type'   => 'datamatrix',
    'format' => 'png',
    'width'  => 10,
    'height' => 10,
    'color'  => array(127, 127, 127),
);

$barcode =
    $this->get('skies_barcode.generator')->generate($options);

return new Response('<img src="data:image/png;base64,'.$barcode.'" />');

For format png, the generator return the based64 of png file, so you can get the real data of png by base64_decode($barcode). Here we use Data URI scheme to direct display the png in webpage., (*12)

Usage in Twig template

This bundle extend one function of Twig: barcode which you can simply use it to generate barcode in the twig template., (*13)

barcode use the same options, only different thing is your need pass a Twig array (it looks really like Json, but it isn't) in the function., (*14)

  • display html
{{ barcode({code: 'string to encode', type: 'c128', format: 'html'}) }}
  • display svg
{{ barcode({code: 'string to encode', type: 'qrcode', format: 'svg', width: 10, height: 10, color: 'green'}) }}
  • display png
<img src="data:image/png;base64,
{{ barcode({code: 'string to encode', type: 'datamatrix', format: 'png', width: 10, height: 10, color: [127, 127, 127]}) }}
" />

Usage without service

use Skies\SkiesQRcodeBundle\Generator\Generator;
//...
$options = array(
    'code'   => 'string to encode',
    'type'   => 'qrcode',
    'format' => 'html',
);

$generator = new Generator();
$barcode = $generator->generate($options);

return new Response($barcode);

Save Barcode in file

As you can see, the Bundle save nothing on the file system, But if you want to keep the barcode, No problem!, (*15)

  • save as html
$savePath = '/tmp/';
$fileName = 'sample.html';

file_put_contents($savePath.$fileName, $barcode);
  • save as svg
$savePath = '/tmp/';
$fileName = 'sample.svg';

file_put_contents($savePath.$fileName, $barcode);
  • save as png
$savePath = '/tmp/';
$fileName = 'sample.png';

file_put_contents($savePath.$fileName, base64_decode($barcode));

Supported Barcode Types

Please read Wikipedia page to know which type you should choice., (*16)

2d barcodes

type Name Example(encode 123456)
qrcode QR code
pdf417 PDF417
datamatrix Data Matrix

1d barcodes

type Symbology Example(encode 123456)
c39 Code 39
c39+ Code 39 CHECK_DIGIT
c39e Code 39 EXTENDED
c39e+ Code 39 EXTENDED CHECK_DIGIT
c93 Code 93
s25 Standard 2 of 5
s25+ Standard 2 of 5 CHECK_DIGIT
i25 Interleaved 2 of 5
i25+ Interleaved 2 of 5 CHECK_DIGIT
c128 Code 128
c128a Code 128A
c128b Code 128B
c128c Code 128C
ean2 EAN 2
ean5 EAN 5
ean8 EAN 8
ean13 EAN 13
upca UPC-A
upce UPC-B
msi MSI
msi+ MSI CHECK_DIGIT
postnet POSTNET
planet PLANET
rms4cc RMS4CC
kix KIX-code
imb IM barcode
codabar Codabar
code11 Code 11
pharma Pharmacode
pharma2t Pharmacode Two-Track

Requirements

If there is some problem of requirements, make sure you have install these two extensions of PHP (check in your phpinfo())., (*17)

  • Barcodes requires GD and ImageMagick to create PNGs in PHP 5.3.
  • Barcodes requires PHP bcmath extension for Intelligent Mail barcodes

Tests

To execute unit tests:, (*18)

$ phpunit --coverage-text

The Versions

29/07 2018

dev-master

9999999-dev

Symfony2Barcode Generator Bundle with Twig function extension

  Sources   Download

Apache-2.0 GNU-LGPLv3

The Requires

 

The Development Requires

twig symfony2 bundle generator symfony3 symfony qrcode barcode qr code symfony4

29/07 2018

1.2.6

1.2.6.0

Symfony2Barcode Generator Bundle with Twig function extension

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

twig symfony2 bundle generator symfony3 symfony qrcode barcode qr code symfony4

31/12 2017

1.2.5

1.2.5.0

Symfony2Barcode Generator Bundle with Twig function extension

  Sources   Download

GNU-LGPLv3

The Requires

 

The Development Requires

twig symfony2 bundle generator symfony qrcode barcode qr code

28/10 2017

v1.2.4

1.2.4.0

Symfony2Barcode Generator Bundle with Twig function extension

  Sources   Download

GNU-LGPLv3

The Requires

 

The Development Requires

twig symfony2 bundle generator symfony qrcode barcode qr code

23/01 2017

v1.2.3

1.2.3.0

Symfony2Barcode Generator Bundle with Twig function extension

  Sources   Download

GNU-LGPLv3

The Requires

 

The Development Requires

twig symfony2 bundle generator symfony qrcode barcode qr code

05/10 2016

v1.2.2

1.2.2.0

Symfony2Barcode Generator Bundle with Twig function extension

  Sources   Download

GNU-LGPLv3

The Requires

 

The Development Requires

twig symfony2 bundle generator symfony qrcode barcode qr code

30/09 2016

v1.2.1

1.2.1.0

Symfony2Barcode Generator Bundle with Twig function extension

  Sources   Download

GNU-LGPLv3

The Requires

 

The Development Requires

twig symfony2 bundle generator symfony qrcode barcode qr code

30/09 2016

v0.0.1

0.0.1.0

Symfony2Barcode Generator Bundle with Twig function extension

  Sources   Download

GNU-LGPLv3

The Requires

 

The Development Requires

twig symfony2 bundle generator symfony qrcode barcode qr code

30/09 2016

1.0.0

1.0.0.0

Symfony2Barcode Generator Bundle with Twig function extension

  Sources   Download

GNU-LGPLv3

The Requires

 

The Development Requires

twig symfony2 bundle generator symfony qrcode barcode qr code

30/09 2016

v1.2.0

1.2.0.0

Symfony2Barcode Generator Bundle with Twig function extension

  Sources   Download

GNU-LGPLv3

The Requires

 

The Development Requires

twig symfony2 bundle generator symfony qrcode barcode qr code