PHP code example of rafikhaceb / pi-barcode

1. Go to this page and download the library: Download rafikhaceb/pi-barcode library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rafikhaceb / pi-barcode example snippets


// initialisation
use PiBarCode\PiBarCodeGenerator;

PiBarCodeGenerator::generate('123456789012', 'EAN', 150, 0, true);

// initialisation
use PiBarCode\PiBarCode;

$bc = new PiBarCode();
  
// Code to generate
$bc->setCode('123456789012');

// Set code type : EAN, UPC, C39...
$bc->setType('EAN');

// Image size (height, width, quiet areas)
//    min Height = 15px
//    image width (can not be less than the space needed for the barcode)
//    quiet areas (mini = 10px) to the left and to the right of barcode
$bc->setSize(150);
  
// Text under the bars :
//    'AUTO' : displays the barcode value
//    '' : does not display text under the code
//    'text to display' : displays a free textu nder the bars
//$bc->setText('AUTO');
  
// If called, this method disables code type printing (EAN, C128...)
$bc->hideCodeType();
  
// Colors of the Bars and the Background in the format '#rrggbb'
$bc->setColors('#123456', '#F9F9F9');

// File type: GIF or PNG (default)
$bc->setFileType('PNG');
  
// Send the image to a file
//$bc->writeBarcodeFile('barcode.png');

// Or send the image to the browser
$bc->showBarcodeImage();