Barcodes On your Web apps


The bar code is method of automatic identification and data collection.
Their use is widespread and the technology behind barcodes is constantly improving. Almost every item purchased from a grocery store, department store, and mass merchandiser has a UPC barcode on it. Now rarely will one come across any product that doesn’t have a barcode.

Varieties of barcodes
Barcodes bascially come in two main type: linear (1-dimensional) and Matrix (2-dimensional) with each offering a variety of formats, depending on your application purpose

(1) linear (1-dimensional) : The barcodes we usually see on books and other standard products are of the linear type. These only encode data in one dimension, from left to right. The following shows a typical UPC barcode.
(2) Matrix (2-dimensional) : They also come in patterns of squares, dots, hexagons and other geometric patterns within images termed 2D (2 dimensional) matrix codes or symbologies.

It is to use the PEAR::Image_Barcode class in PHP to dynamically create barcodes for Web applications. The backbone to the PEAR::Image_Barcode's ability to produce barcode images is in the GD library,If you haven't already installed PEAR, you will need to do so in order to get this application to work.


Installation
You can install Image_Barcode issuing the following command (as root):
# pear install Image_Barcode

You can get the latest code at the PEAR site:
http://pear.php.net/package/Image_Barcode/


Using Image_Barcode
Creating a barcode is as simple as calling the classes static draw() method.
The method has four parameters:

Text : string that shall be converted into barcode representation.
Type : this parameter determines which driver/type should be used; it is one of: Code39, code128, ean13, int25, postnet or upca.
Imgtype : determines the type of the image that is generated; one of jpg, png and gif.

By default, the image generated by the barcode driver is directly output to the browser. If you do not want this, pass false as fourth parameter and draw() will return the GD image resource object; allowing you to do further things with it.

Example code
A sample code for generating a CODE128 barcode is shown below.

/* Data that will be encoded in the bar code */
$bar_code_data = "TRSD5656";

/* The third parameter can accept any from the following,
* jpg, png and gif.
*/
Image_Barcode::draw($bar_code_data, 'code128', 'png');
?>

Supported Types
The ‘Image_Barcode’ library supports the following barcode types:
* Code 39
* Code 128
* EAN 13
* INT 25
* PostNet
* UPCA

No comments: