Barcode generator for PHP logo

Whilst fiddling around with QR Codes, I came across this Bar-code generator for PHP.

Minimum requirements:

  • PHP 5
  • GD2 Extension

Here is my code for a basic implementation (adapted from the manual which has errors):

<?php
require_once('class/BCGFontFile.php');
require_once('class/BCGColor.php');
require_once('class/BCGDrawing.php');
require_once('class/BCGcode128.barcode.php');

// The arguments are R, G, and B for color.
$colorBack = new BCGColor(255, 255, 255);
$code = new BCGcode128(); // Or another class name from the manual
$code->parse('BARCODE'); // Text
$image_name = 'mybc.png';
$drawing = new BCGDrawing($image_name, $colorBack);
$drawing->setBarcode($code);
$drawing->draw();

header('Content-Type: image/png');

$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
echo '<img src="'.$image_name.'" />';
?>

http://barcodephp.com/

By foxbeefly

PHP / MySQL Developer

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.