- Saved searches
- Use saved searches to filter your results more quickly
- License
- brewerwall/php-barcode-generator
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- Readme.md
- About
- Saved searches
- Use saved searches to filter your results more quickly
- License
- picqer/php-barcode-generator
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- Readme.md
- About
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
This is an easy to use, non-bloated, framework independent, barcode generator in PHP. An updated version of `picqer/php-barcode-generator`
License
brewerwall/php-barcode-generator
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
Readme.md
This is an easy to use, non-bloated, framework independent, barcode generator in PHP. This version has been updated to follow PSR-4 and work with PHP 7.1+.
It creates SVG, PNG, JPG and HTML images, from the most used 1D barcode standards.
The codebase is largely from the TCPDF barcode generator by Nicola Asuni. This code is therefor licensed under LGPLv3. It is still a bit of a mess, bit I will clean it in the future. I do not expect the interface of this class will change during the clean ups.
This codebase, also extending off of TCPDF barcode generator is a mostly direct copy from Picqer barcode generator. Updated to be php 7.1+ compliant.
composer require brewerwall/php-barcode-generator
If you want to generate PNG or JPG images, you need the GD library or Imagick installed on your system as well.
Using IMB Barcodes require bcmath extension to be installed as well.
Create a new barcode generator. This will declare the code, the type of barcode and what format the code will be rendered.
$generator = new BarcodeGenerator(BarcodeType::TYPE_CODE_128, BarcodeRender::RENDER_JPG); // Generate our code $generated = $generator->generate('012345678'); // Generates the same code with style updates $generated = $generator->generate('012345678', 4, 50, '#FFCC33');
The $generator->generate() method accepts the following parameters:
- $code Barcode value we need to generate.
- $widthFactor (default: 2) Width is based on the length of the data, with this factor you can make the barcode bars wider than default
- $totalHeight (default: 30) The total height of the barcode
- $color (default: #000000) Hex code of the foreground color
use Brewerwall\Barcode\Constants\BarcodeRender; BarcodeRender::RENDER_JPG BarcodeRender::RENDER_PNG BarcodeRender::RENDER_HTML BarcodeRender::RENDER_SVG
use Brewerwall\Barcode\Constants\BarcodeType; BarcodeType::TYPE_CODE_39 BarcodeType::TYPE_CODE_39_CHECKSUM BarcodeType::TYPE_CODE_39E BarcodeType::TYPE_CODE_39E_CHECKSUM BarcodeType::TYPE_CODE_93 BarcodeType::TYPE_STANDARD_2_5 BarcodeType::TYPE_STANDARD_2_5_CHECKSUM BarcodeType::TYPE_INTERLEAVED_2_5 BarcodeType::TYPE_INTERLEAVED_2_5_CHECKSUM BarcodeType::TYPE_CODE_128 BarcodeType::TYPE_CODE_128_A BarcodeType::TYPE_CODE_128_B BarcodeType::TYPE_CODE_128_C BarcodeType::TYPE_EAN_2 BarcodeType::TYPE_EAN_5 BarcodeType::TYPE_EAN_8 BarcodeType::TYPE_EAN_13 BarcodeType::TYPE_UPC_A BarcodeType::TYPE_UPC_E BarcodeType::TYPE_MSI BarcodeType::TYPE_MSI_CHECKSUM BarcodeType::TYPE_POSTNET BarcodeType::TYPE_PLANET BarcodeType::TYPE_RMS4CC BarcodeType::TYPE_KIX BarcodeType::TYPE_IMB BarcodeType::TYPE_CODABAR BarcodeType::TYPE_CODE_11 BarcodeType::TYPE_PHARMA_CODE BarcodeType::TYPE_PHARMA_CODE_TWO_TRACKS
Embedded PNG image in HTML:
$generator = new BarcodeGenerator(BarcodeType::TYPE_CODE_128, BarcodeRender::RENDER_PNG); echo '$generator->generate('012345678')) . '">';
About
This is an easy to use, non-bloated, framework independent, barcode generator in PHP. An updated version of `picqer/php-barcode-generator`
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Barcode generator in PHP that is easy to use, non-bloated and framework independent.
License
picqer/php-barcode-generator
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
Readme.md
This is an easy to use, non-bloated, framework independent, barcode generator in PHP.
It creates SVG, PNG, JPG and HTML images, from the most used 1D barcode standards.
The codebase is based on the TCPDF barcode generator by Nicola Asuni. This code is therefor licensed under LGPLv3.
- No support for any 2D barcodes, like QR codes.
- We only generate the ‘bars’ part of a barcode, without text below the barcode. If you want text of the code below the barcode, you could add it later to the output of this package.
composer require picqer/php-barcode-generator
If you want to generate PNG or JPG images, you need the GD library or Imagick installed on your system as well.
Initiate the barcode generator for the output you want, then call the ->getBarcode() routine as many times as you want.
require 'vendor/autoload.php'; // This will output the barcode as HTML output to display in the browser $generator = new Picqer\Barcode\BarcodeGeneratorHTML(); echo $generator->getBarcode('081231723897', $generator::TYPE_CODE_128);
The getBarcode() method accepts the following parameters:
- $barcode String needed to encode in the barcode
- $type Type of barcode, use the constants defined in the class
- $widthFactor Width is based on the length of the data, with this factor you can make the barcode bars wider than default
- $height The total height of the barcode in pixels
- $foregroundColor Hex code as string, or array of RGB, of the colors of the bars (the foreground color)
Example of usage of all parameters:
require 'vendor/autoload.php'; $redColor = [255, 0, 0]; $generator = new Picqer\Barcode\BarcodeGeneratorPNG(); file_put_contents('barcode.png', $generator->getBarcode('081231723897', $generator::TYPE_CODE_128, 3, 50, $redColor));
$generatorSVG = new Picqer\Barcode\BarcodeGeneratorSVG(); // Vector based SVG $generatorPNG = new Picqer\Barcode\BarcodeGeneratorPNG(); // Pixel based PNG $generatorJPG = new Picqer\Barcode\BarcodeGeneratorJPG(); // Pixel based JPG $generatorHTML = new Picqer\Barcode\BarcodeGeneratorHTML(); // Pixel based HTML $generatorHTML = new Picqer\Barcode\BarcodeGeneratorDynamicHTML(); // Vector based HTML
These barcode types are supported. All types support different character sets or have mandatory lengths. Please see wikipedia for supported chars and lengths per type.
Most used types are TYPE_CODE_128 and TYPE_CODE_39. Because of the best scanner support, variable length and most chars supported.
- TYPE_CODE_32 (italian pharmaceutical code ‘MINSAN’)
- TYPE_CODE_39
- TYPE_CODE_39_CHECKSUM
- TYPE_CODE_39E
- TYPE_CODE_39E_CHECKSUM
- TYPE_CODE_93
- TYPE_STANDARD_2_5
- TYPE_STANDARD_2_5_CHECKSUM
- TYPE_INTERLEAVED_2_5
- TYPE_INTERLEAVED_2_5_CHECKSUM
- TYPE_CODE_128
- TYPE_CODE_128_A
- TYPE_CODE_128_B
- TYPE_CODE_128_C
- TYPE_EAN_2
- TYPE_EAN_5
- TYPE_EAN_8
- TYPE_EAN_13
- TYPE_ITF14 (Also known as GTIN-14)
- TYPE_UPC_A
- TYPE_UPC_E
- TYPE_MSI
- TYPE_MSI_CHECKSUM
- TYPE_POSTNET
- TYPE_PLANET
- TYPE_RMS4CC
- TYPE_KIX
- TYPE_IMB
- TYPE_CODABAR
- TYPE_CODE_11
- TYPE_PHARMA_CODE
- TYPE_PHARMA_CODE_TWO_TRACKS
A note about PNG and JPG images
If you want to use PNG or JPG images, you need to install Imagick or the GD library. This package will use Imagick if that is installed, or fall back to GD. If you have both installed but you want a specific method, you can use $generator->useGd() or $generator->useImagick() to force your preference.
Embedded PNG image in HTML
$generator = new Picqer\Barcode\BarcodeGeneratorPNG(); echo '$generator->getBarcode('081231723897', $generator::TYPE_CODE_128)) . '">';
$generator = new Picqer\Barcode\BarcodeGeneratorJPG(); file_put_contents('barcode.jpg', $generator->getBarcode('081231723897', $generator::TYPE_CODABAR));
Oneliner SVG output to disk
file_put_contents('barcode.svg', (new Picqer\Barcode\BarcodeGeneratorSVG())->getBarcode('6825ME601', Picqer\Barcode\BarcodeGeneratorSVG::TYPE_KIX));
About
Barcode generator in PHP that is easy to use, non-bloated and framework independent.