How to Create a Barcode using PHP
Submitted by nurhodelta_17 on Monday, April 2, 2018 - 22:26.
Getting Started
To be able to generate barcode, I've used an existing Barcode class in Github. I have downloaded the files in the Repo and are included in the downloadable of this tutorial but if you want, you can download the class yourself. 1. Install composer. If you have not installed composer yet, you may download it using this link. 2. Once composer is installed, create your directory, in my case barcode_php. 3. Navigate to your created directory in command prompt and type in:- composer require picqer/php-barcode-generator
Generating our Barcode
Next, we are going to generate our barcode, as you can see in the Github Repo, you can use different barcode types. As an example, create a new file, name it as index.php and paste the codes below.- <?php
- require 'vendor/autoload.php';
- $generator = new \Picqer\Barcode\BarcodeGeneratorPNG();
- echo '<img src="data:image/png;base64,' . base64_encode($generator->getBarcode('081231723897', $generator::TYPE_CODE_128)) . '">';
- ?>
Add new comment
- 961 views