User guide

Installation

You must have installed the following program and extension:

  • PHP 5
  • GD2 Extension

To add other fonts, simply copy .ttf fonts to the font folder.
* For PDF417, BCMath is required.

Creating Barcodes

The following code explains to you step by step how to create barcodes.
Check the manual to obtain more information on the available methods.

First, you must include the required files to draw your barcode:

require_once('class/BCGFontFile.php');
require_once('class/BCGColor.php');
require_once('class/BCGDrawing.php');

Next, you must include the file of your barcode type.

require_once('class/.php');

Let's generate some colors:

// The arguments are R, G, and B for color.
$colorFront = new BCGColor(0, 0, 0);
$colorBack = new BCGColor(255, 255, 255);

We will now load the font for writing a label under the barcode. If you don't desire to have a text label, ignore this step.
The first argument is the path to the ttf font file and the second is the size in point (pt) of the font.)

$font = new BCGFontFile('./class/font/Arial.ttf', 18);

Now, we will create the barcode. There is no parameter for the class constructor; you must call the provided methods to modify the barcode properties (see the manual). At the end of the code, you must call the function parse() in order to analyze the code you want to draw.

$code = new BCGcode39(); // Or another class name from the manual
$code->setScale(2); // Resolution
$code->setThickness(30); // Thickness
$code->setForegroundColor($color_black); // Color of bars
$code->setBackgroundColor($color_white); // Color of spaces
$code->setFont($font); // Font (or 0)
$code->parse('HELLO'); // Text

In this part, you must put the barcode on a drawing image. We use the BCGDrawing class, but you can use any other class that draws an image to a file or displays it on the screen. The first argument is the filename. If this is empty, the image will appear on the screen. The last argument is the background color.

$drawing = new BCGDrawing('', $colorfg);
$drawing->setBarcode($code);
$drawing->draw();

We will now change the header to direct the browser to output an image. If you output it to a file, you don't have to insert this line. If the image is a jpg, you must modify it.

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

To finish, call the finish method with the argument BCGDrawing::IMG_FORMAT_PNG or BCGDrawing::IMG_FORMAT_JPEG to have a png or a jpg file. If you have specified a filename before, the image will be saved into this file, otherwise it will be displayed.

$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);

Reading Barcodes

Maybe you are wondering how to read barcodes? You need a barcode reader to do this. For 2D barcode readers, the best known is CCD. This reader is digital and does not contain a laser. This kind of scanner can decode barcodes you have generated with Barcode Generator if your reader can decode the symbology you chose.

What resolution should you choose? We advise that you choose the default resolution for barcodes, but you can set it to be smaller or larger. If you make it smaller, you will have to keep your scanner closer the barcode to read it correctly. If you set it to be larger, and your barcode is bigger, you can read from further away.