Barcode generator for PHP logoBarcode generator for PHP logo

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

In this post:
  1. Minimum requirements
  2. Code

1. Minimum requirements

Your server configuration must comply with the following:

  • PHP 5
  • GD2 Extension

2. Code

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.'" />';
?>

References:

  1. Dependable barcode generation software to simplify your business. (no date) Barcode Bakery. Available at: https://www.barcodebakery.com/ (Accessed: 9 March 2024).

By MisterFoxOnline

CAT Educator

Leave a Reply

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

Discover more from stylus

Subscribe now to keep reading and get access to the full archive.

Continue reading