Developed with love by KnpLabs Hire us for your project!
81

MopaBarcodeBundle

by phiamo

Bundle to provide Barcodes in Symfony2

README

Introduction

MopaBarcodeBundle integrates Zend_Barcode and PHP QR Lib to be easily used in symfony2 via twig.
I did include phpqrcode form http://sourceforge.net/projects/phpqrcode/ due to changes in its config.
Is just a shot and shouldnt be considered to be perfect. Feel free to fork and PR.

Prerequisites

Installation

  1. Add this bundle to your composer.json:

    {
    "require": {
    // ...
    "mopa/barcode-bundle": "dev-master",
    "avalanche123/imagine-bundle": "dev-master", // handles image installation via requirements
    // if you want to use the zend barcodes
    "zendframework/zendframework": "2.1.3" // version is the latest known to work, might be newer will too
    // optionally for playground
    "mopa/bootstrap-sandbox-bundle": "dev-master"
    // also read the readme:
    // https://github.com/phiamo/MopaBootstrapSandboxBundle
    }
    }

  2. Add this bundle to your app/AppKernel.php:

// application/ApplicationKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Avalanche\Bundle\ImagineBundle\AvalancheImagineBundle(),
        new Mopa\Bundle\BarcodeBundle\MopaBarcodeBundle(),
    );
}

Demo

Include MopaBoostrapBundle in your app: https://github.com/phiamo/MopaBootstrapBundle

Include this snipplet in your routing.yml

my_barcode_playground:
    resource: "@MopaBarcodeBundle/Resources/config/routing/barcode_playground.yml"
    prefix:   /

Add this to your config.yml:

imports:
    - { resource: @MopaBootstrapSandboxBundle/Resources/config/examples/example_menu.yml }
    - { resource: @MopaBootstrapSandboxBundle/Resources/config/examples/example_navbar.yml }

And try http://{yoursymfonyapp}/mopa/barcode/playground

Usage

Have a look into the https://github.com/phiamo/MopaBarcodeBundle/blob/master/Controller/BarcodeController.php
to see it in action

Supported Barcode Types depend on your Zend2 installation

If you installed it have a look into
https://github.com/phiamo/MopaBarcodeBundle/blob/master/Model/BarcodeTypes.php
The Type given to the service is either the int or the string defined in the types arrays keys and values

To get the service in your controllers etc you can use

$bmanager = $this->container->get('mopa_barcode.barcode_service');

$bmanager->saveAs($type, $text, $file);
to save a Barcode of $type with $text as $file or

$bmanager->get($type, $enctext, $absolute = false);
to get the url to the file
where $enctext is urlencoded and $absolute is an boolean to get either the absolute or the relative path (default)

Twig Helper

There is also a twig helper registered:

        <p><img alt="[barcode]" src="{{ mopa_barcode_url('code128', '123456789', {'barcodeOptions': {}, 'rendererOptions': {}}) }}"></p>

Of course the dict (3rd parameter is optional) have a look into http://framework.zend.com/manual/2.1/en/modules/zend.barcode.creation.html
to see what options can be set.

the dict also takes a noCache boolean, i wont explain it further

Using the bundle directly

To Make usage e.g. of the Playground in your app, just copy the playground.html.twig to
app/Resources/MopaBootstrapBundle/views/Barcode/playground.html.twig
and modify as you like

Using the Bundle as a urlservice

If you would like to generate the barcodes on the fly include
in your routing.yml

my_barcode_display:
    resource: "@MopaBarcodeBundle/Resources/config/routing/barcode_display.yml"
    prefix:   /

And just use Urls to generate your barcodes:

http://{yoursymfonyapp}/mopa/barcode/send/{type}/{enctext}

Using QR code overlays

Add this to twig template.

    <img src="{{ mopa_barcode_url('qr', "Text to put in QR code", {'size':2, 'level':3, 'margin':0, 'useOverlay': true}) }}"/>

Changing overlay images

Add and edit this to your parameters.yml file.

mopa_barcode.overlay_images_path: Resources/qr_overlays

For each QR code level (size) you have to generate overlay image. Look in `Resources/qr_overlays' path of bundle for example overlay images.

TODO

- Load the different Barcode Libs in a different way. should't be done by ints :(

Known Issues

- Nothing what could not be done in another way, probably some will arise as soon as its published
  So make issues!
- There are probably things missing, so make PR's
Copyright (c) 2011 Mohrenweiser & Partner, Philipp A. Mohrenweiser
- http://www.mohrenweiserpartner.de

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
mopa_barcode:         []
  • Merge pull request #17 from kmdaniel/issue-16-renderer-options-overwritten
    By phiamo, 4 years ago
  • fixed the renderer options overwrite (github issue-16)
    By kmdaniel, 4 years ago
  • updated readme
    By phiamo, 4 years ago
  • adapted paths
    By phiamo, 4 years ago
  • added examples
    By phiamo, 4 years ago
  • updated url to match ci
    By phiamo, 4 years ago
  • corrected deps
    By phiamo, 4 years ago
  • Added renderer and barcode options to be set via options
    By phiamo, 4 years ago
  • Added default arrays for bc compat
    By phiamo, 4 years ago
  • Changed back to imagine, just for bc compat
    By phiamo, 4 years ago
  • Merge pull request #15 from matejvelikonja/patch-1
    By phiamo, 4 years ago
  • Update Model/BarcodeService.php
    By matejvelikonja, 4 years ago
  • Merge pull request #14 from dpokleka/master
    By phiamo, 4 years ago
  • Added noCache option.
    By matejvelikonja, 4 years ago
  • Fixed readme. Added optional config for overlay images.
    By matejvelikonja, 4 years ago
  • added download action for barcodes codes
    By dpokleka, 4 years ago
  • - properly implemented resizing of overlay according to size option
    By dpokleka, 4 years ago
  • - added stuff necessary to overlay images onto QR code
    By dpokleka, 4 years ago
  • - corrected cahce output-dir
    By dpokleka, 4 years ago
  • Allow options for QR code.
    By EricReiche, 4 years ago
  • Allow URLs as QR content.
    By EricReiche, 4 years ago
  • Merge pull request #11 from garciaf/patch-1
    By phiamo, 4 years ago
  • Update README.md
    By garciaf, 4 years ago
  • Merge pull request #5 from pachay/master
    By phiamo, 4 years ago
  • Merge pull request #7 from neoshadybeat/master
    By phiamo, 4 years ago
  • Merge pull request #8 from garciaf/ImagineWebRootConfig
    By phiamo, 4 years ago
  • Merge remote-tracking branch 'remotes/origin/patch-1'
    By garciaf, 4 years ago
  • Update Resources/config/services.xml
    By garciaf, 4 years ago
  • Update Model/BarcodeService.php
    By garciaf, 4 years ago
  • fix, package name of zf
    By neoshadybeat, 4 years ago