{"id":15077829,"url":"https://github.com/chrisandchris/barcode-bundle","last_synced_at":"2025-10-05T11:32:06.992Z","repository":{"id":56952306,"uuid":"59963247","full_name":"chrisandchris/barcode-bundle","owner":"chrisandchris","description":"Symfony Barcode Bundle that generates various barcode types","archived":true,"fork":false,"pushed_at":"2018-02-28T15:35:16.000Z","size":107,"stargazers_count":9,"open_issues_count":1,"forks_count":18,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-26T04:32:44.634Z","etag":null,"topics":["barcode","barcode-bundle","sgkbarcodebundle","symfony"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chrisandchris.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-29T20:49:40.000Z","updated_at":"2023-01-28T10:41:38.000Z","dependencies_parsed_at":"2022-08-21T09:20:20.768Z","dependency_job_id":null,"html_url":"https://github.com/chrisandchris/barcode-bundle","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisandchris%2Fbarcode-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisandchris%2Fbarcode-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisandchris%2Fbarcode-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisandchris%2Fbarcode-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrisandchris","download_url":"https://codeload.github.com/chrisandchris/barcode-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219876996,"owners_count":16554814,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["barcode","barcode-bundle","sgkbarcodebundle","symfony"],"created_at":"2024-09-25T04:32:42.300Z","updated_at":"2025-10-05T11:32:01.697Z","avatar_url":"https://github.com/chrisandchris.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SGKBarcodeBundle\n\nSGKBarcodeBundle is a Symfony3 / 4 Barcode Generator Bundle.\n\nFeatures:\n\n1. Support 3 two-dimensional (2D) and 30 one-dimensional (1D) Barcode types\n2. Three output formats: HTML, PNG and SVG canvas\n3. Twig integration: you can simply use a extensional function of Twig in the template to generate Barcode\n4. Core of this bundle from this project [tc-lib-barcode](https://github.com/tecnickcom/tc-lib-barcode)\n\n![SGKBarcodeBundle](Resources/doc/README.png)\n\n## Installation\n\nAdd SGKBarcodeBundle by running the command:\n```sh\n$ php composer.phar require sgk/barcode-bundle:v2.0.0\n```\n\nOr, add SGKBarcodeBundle to your ``composer.json``, then execute ``php composer.phar update``\n```json\n\"require\": {\n        \"sgk/barcode-bundle\": \"v2.0.0\"\n    }\n```\n\nComposer will install the bundle to your project's vendor/sgk directory.\n\nThen, Enable the bundle in the kernel:\n```php\n\u003c?php\n// app/AppKernel.php\n\npublic function registerBundles()\n{\n    $bundles = array(\n        // ...\n        new SGK\\BarcodeBundle\\SGKBarcodeBundle(),\n    );\n}\n```\n\nIf you are using Symfony 4 with Flex the line should have automatically been added to `config/bundles.php`\n\n## Generate options\n\nTo generate one barcode, you have 5 options can be configured.\n\n|option|type       |required|allowed values|description          |\n|:----:|:---------:|:------:|:------------:|:-------------------:|\n|code  |string     |required|              |what you want encoded|\n|type  |string     |required|[Supported Types](#supported-barcode-types)|type of barcode|\n|format|string     |required|html, svg, png|output format|\n|width |**integer**|optional|              |**width of unit**|\n|height|**integer**|optional|              |**height of unit**|\n|color |string for html, svg / array for png|optional|[HTML Color Names](http://www.w3schools.com/html/html_colornames.asp) / array(R, G, B)|barcode color|\n\n\u003e Default width and height for 2D barcode are 5, 5, for 1D are 2, 30.\n\u003e Default color for html, svg is black, for png is array(0, 0, 0)\n\n## Usage by service\n\n\u003e This is deprecated in version 3.4 and will break in Symfony 4. See 'usage without service' instead.\n\nThe bundle registers one service: ``sgk_barcode.generator`` which will allows you to generate barcode:\n\n* outpout html\n```php\n$options = array(\n    'code'   =\u003e 'string to encode',\n    'type'   =\u003e 'c128',\n    'format' =\u003e 'html',\n);\n\n$barcode =\n    $this-\u003eget('sgk_barcode.generator')-\u003egenerate($options);\n    \nreturn new Response($barcode);\n```\n\n* outpout svg\n```php\n$options = array(\n    'code'   =\u003e 'string to encode',\n    'type'   =\u003e 'qrcode',\n    'format' =\u003e 'svg',\n    'width'  =\u003e 10,\n    'height' =\u003e 10,\n    'color'  =\u003e 'green',\n);\n\n$barcode =\n    $this-\u003eget('sgk_barcode.generator')-\u003egenerate($options);\n    \nreturn new Response($barcode);\n```\n\n* outpout png\n```php\n$options = array(\n    'code'   =\u003e 'string to encode',\n    'type'   =\u003e 'datamatrix',\n    'format' =\u003e 'png',\n    'width'  =\u003e 10,\n    'height' =\u003e 10,\n    'color'  =\u003e array(127, 127, 127),\n);\n\n$barcode =\n    $this-\u003eget('sgk_barcode.generator')-\u003egenerate($options);\n\nreturn new Response('\u003cimg src=\"data:image/png;base64,'.$barcode.'\" /\u003e');\n```\n\u003e 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](http://en.wikipedia.org/wiki/Data_URI_scheme) to direct display the png in webpage.\n\n## Usage in Twig template\n\nThis bundle extend one function of Twig: ``barcode`` which you can simply use it to generate barcode in the twig template.\n\n``barcode`` use the same options, only different thing is your need pass a [Twig array](http://twig.sensiolabs.org/doc/templates.html#literals) (it looks really like Json, but it isn't) in the function.\n\n* display html\n```twig\n{{ barcode({code: 'string to encode', type: 'c128', format: 'html'}) }}\n```\n\n* display svg\n```twig\n{{ barcode({code: 'string to encode', type: 'qrcode', format: 'svg', width: 10, height: 10, color: 'green'}) }}\n```\n\n* display png\n```twig\n\u003cimg src=\"data:image/png;base64,\n{{ barcode({code: 'string to encode', type: 'datamatrix', format: 'png', width: 10, height: 10, color: [127, 127, 127]}) }}\n\" /\u003e\n```\n\n## Usage without service\n\n```php\nuse SGK\\BarcodeBundle\\Generator\\Generator;\n//...\n$options = array(\n    'code'   =\u003e 'string to encode',\n    'type'   =\u003e 'qrcode',\n    'format' =\u003e 'html',\n);\n\n$generator = new Generator();\n$barcode = $generator-\u003egenerate($options);\n\nreturn new Response($barcode);\n```\n\n## Save Barcode in file\n\nAs you can see, the Bundle save nothing on the file system, But if you want to keep the barcode, No problem!\n\n* save as html\n```php\n$savePath = '/tmp/';\n$fileName = 'sample.html';\n\nfile_put_contents($savePath.$fileName, $barcode);\n```\n\n* save as svg\n```php\n$savePath = '/tmp/';\n$fileName = 'sample.svg';\n\nfile_put_contents($savePath.$fileName, $barcode);\n```\n\n* save as png\n```php\n$savePath = '/tmp/';\n$fileName = 'sample.png';\n\nfile_put_contents($savePath.$fileName, base64_decode($barcode));\n```\n\n## Supported Barcode Types\n\nPlease read [Wikipedia page](http://en.wikipedia.org/wiki/Barcode) to know which type you should choice. \n\n### 2d barcodes\n\n|type      |Name                                                   |Example(encode 123456)|\n|:--------:|:-----------------------------------------------------:|:--------------------:|\n|qrcode    |[QR code](http://en.wikipedia.org/wiki/QR_code)        |![](Resources/doc/barcode/qrcode.png)|\n|pdf417    |[PDF417](http://en.wikipedia.org/wiki/PDF417)          |![](Resources/doc/barcode/pdf417.png)|\n|datamatrix|[Data Matrix](http://en.wikipedia.org/wiki/Data_Matrix)|![](Resources/doc/barcode/datamatrix.png)|\n\n### 1d barcodes\n\n|type    |Symbology                                              |Example(encode 123456)|\n|:------:|:-----------------------------------------------------:|:--------------------:|\n|c39     |[Code 39](http://en.wikipedia.org/wiki/Code_39)        |![](Resources/doc/barcode/c39.png)|\n|c39+    |Code 39 CHECK_DIGIT                                    |![](Resources/doc/barcode/c39+.png)|\n|c39e    |Code 39 EXTENDED                                       |![](Resources/doc/barcode/c39e.png)|\n|c39e+   |Code 39 EXTENDED CHECK_DIGIT                           |![](Resources/doc/barcode/c39e+.png)|\n|c93     |[Code 93](http://en.wikipedia.org/wiki/Code_93)        |![](Resources/doc/barcode/c93.png)|\n|s25     |[Standard 2 of 5](http://www.barcodeisland.com/2of5.phtml)           |![](Resources/doc/barcode/s25.png)|\n|s25+    |Standard 2 of 5 CHECK_DIGIT                                          |![](Resources/doc/barcode/s25+.png)|\n|i25     |[Interleaved 2 of 5](http://en.wikipedia.org/wiki/Interleaved_2_of_5)|![](Resources/doc/barcode/i25.png)|\n|i25+    |Interleaved 2 of 5 CHECK_DIGIT                                       |![](Resources/doc/barcode/i25+.png)|\n|c128    |[Code 128](http://en.wikipedia.org/wiki/Code_128)                    |![](Resources/doc/barcode/c128.png)|\n|c128a   |Code 128A|![](Resources/doc/barcode/c128a.png)|\n|c128b   |Code 128B|![](Resources/doc/barcode/c128b.png)|\n|c128c   |Code 128C|![](Resources/doc/barcode/c128c.png)|\n|ean2    |[EAN 2](http://en.wikipedia.org/wiki/EAN_2)                 |![](Resources/doc/barcode/ean2.png)|\n|ean5    |[EAN 5](http://en.wikipedia.org/wiki/EAN_5)                 |![](Resources/doc/barcode/ean5.png)|\n|ean8    |[EAN 8](http://en.wikipedia.org/wiki/EAN-8)                 |![](Resources/doc/barcode/ean8.png)|\n|ean13   |[EAN 13](http://en.wikipedia.org/wiki/EAN-13)               |![](Resources/doc/barcode/ean13.png)|\n|upca    |[UPC-A](http://en.wikipedia.org/wiki/Universal_Product_Code)|![](Resources/doc/barcode/upca.png)|\n|upce    |[UPC-B](http://en.wikipedia.org/wiki/Universal_Product_Code)|![](Resources/doc/barcode/upce.png)|\n|msi     |[MSI](http://en.wikipedia.org/wiki/MSI_Barcode)             |![](Resources/doc/barcode/msi.png)|\n|msi+    |MSI CHECK_DIGIT                                             |![](Resources/doc/barcode/msi+.png)|\n|postnet |[POSTNET](http://en.wikipedia.org/wiki/POSTNET)             |![](Resources/doc/barcode/postnet.png)|\n|planet  |[PLANET](http://en.wikipedia.org/wiki/Postal_Alpha_Numeric_Encoding_Technique)|![](Resources/doc/barcode/planet.png)|\n|rms4cc|[RMS4CC](http://en.wikipedia.org/wiki/RM4SCC)    |![](Resources/doc/barcode/rms4cc.png)|\n|kix     |[KIX-code](http://nl.wikipedia.org/wiki/KIX-code)|![](Resources/doc/barcode/kix.png)|\n|imb     |[IM barcode](http://en.wikipedia.org/wiki/Intelligent_Mail_barcode)|![](Resources/doc/barcode/imb.png)|\n|codabar |[Codabar](http://en.wikipedia.org/wiki/Codabar)                    |![](Resources/doc/barcode/codabar.png)|\n|code11  |[Code 11](http://en.wikipedia.org/wiki/Code_11)                    |![](Resources/doc/barcode/code11.png)|\n|pharma  |[Pharmacode](http://en.wikipedia.org/wiki/Pharmacode)              |![](Resources/doc/barcode/pharma.png)|\n|pharma2t|Pharmacode Two-Track                                               |![](Resources/doc/barcode/pharma2t.png)|\n\n## Requirements\n\nIf there is some problem of requirements, make sure you have install these two extensions of PHP (check in your phpinfo()).\n\n- Barcodes requires [GD](http://php.net/manual/en/book.image.php) and [ImageMagick](http://php.net/manual/en/book.imagick.php) to create PNGs in PHP 5.3.\n- Barcodes requires [PHP bcmath](http://php.net/manual/en/book.bc.php) extension for Intelligent Mail barcodes\n\n## Tests\n\nTo execute unit tests, `composer install` and run:\n```sh\nphpunit --coverage-text\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisandchris%2Fbarcode-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisandchris%2Fbarcode-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisandchris%2Fbarcode-bundle/lists"}