Barcode Generator for PHP
Barcode Generator for ASP.NET
Barcode 1D - User Guide

Installation
Program and extensions required:
  • PHP 4 or PHP 5 depending on the version you download
  • GD2 Extension
  • FreeType Extension (to write label)
You can refer to the INSTALL file provided with the ZIP file. When all files are installed correctly, we advise you to modify the line $class_dir = '../class'; to put the absolute path into this variable.
To add other fonts, simply copy .ttf fonts to the class/font folder.

The information in this user guide and the manual are for the version 2.0.0+ of Barcode Generator. It is also based on the PHP5 version of Barcode Generator. The difference between PHP4 is objects are handled differently. When you create objects, you have to use references. Please check the PHP manual for more information.

Creating Barcode
You can use the web application to generate barcode, but if you want to generate it in one of your program, you must understand how the code works.
First of all, you must define a constant variable to prevent "hackers" that go directly into PHP files.
After, you have to include required files to draw your barcode.
require('class/BCGFont.php');
require('class/BCGColor.php');
require('class/BCGDrawing.php');

At this point, you have to include the file of your barcode type. For instance, we will generate a Code39 barcode.
include('class/BCGcode39.barcode.php');

We will now load the font for writing a label under the barcode. If you don't want to have a text on it, 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 BCGFont('./class/font/Arial.ttf', 18);

Ok now, let's generate some colors
// The arguments are R, G, B for color.
$color_black = new BCGColor(0,0,0);
$color_white = new BCGColor(255,255,255);

Now, we have to create the barcode. You don't have any arguments usually used for the constructor; in the other hand, you have to call specified methods to modify the barcode properties (see the manual). To end, you have to call the function parse() in order to analyze the code you want to draw.
$code = new BCGcode39();
$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 have to put the barcode on a drawing image. We use the BCGDrawing class, but you can use any other class which draws an image in a file or displays it on the screen. The first argument is the filename, if this one is empty, the image will appear on the screen. The last argument is the background color.
$drawing = new BCGDrawing('', $color_white);
$drawing->setBarcode($code);
$drawing->draw();

We now change the header to say to the browser that we will output an image. If you output it to a file, you don't have to put 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 Barcode
Maybe you are wondering how to read barcode? You need a barcode reader to read them. There are three popular readers available: Laser beam (like in supermarkets), Camera (no laser, numeric) and laser in pencil or inside slider.
These three can read the barcode you generate with Barcode Generator if your reader can read the technology you chose.
But what resolution you need to choose? Normally, if you have a good reader, you can choose the first resolution, but you will have to stay closer the barcode to read it correctly. So we advise you to use the second resolution. Test it before!
Note: You can't read directly by pointing the laser beam on the computer screen.

Example
Select Language: Français