The software supports the PHP4 and PHP5 two versions, and the PHP5 version is used in this article. Note that the GD module of PHP should be turned on before use. gd.so for Php_gd2.dll,linux in Windows. Extract the compressed file to Apache and execute http://localhost/barcode/index.php. The interface is shown in the following figure:
1.Type: Select barcode type
2.Output: Picture format for output
3.Thickness: Barcode Height
4.Resolution: Barcode Size
5.Font: The text size below the bar code, you can not display text
6.Text: Contents of Barcode printing
Of course, this program is only the text into the bar code, but not flexible to use it embedded in other PHP programs, I will compress the test.php inside the package
Some adjustments have been made to make it flexible for other programs. The runtime simply passes the barcode type and text to test.php, for example:
http://localhost/barcode/test.php?codebar=BCGcode39&text=20090729
or run http://localhost/barcode/mytest.php
mytest.php Code:
Effect Chart:
test.php Code:
<?php
Including all required classes
Require (' class/bcgfont.php ');
Require (' class/bcgcolor.php ');
Require (' class/bcgdrawing.php ');
/* ' Bcgcodabar ', ' BCGcode11 ', ' BCGcode39 ', ' bcgcode39extended ', ' BCGcode93 ',
' BCGcode128 ', ' BCGean8 ', ' BCGean13 ', ' bcgisbn ', ' BCGi25 ', ' BCGs25 ', ' Bcgmsi ',
' BCGUPCA ', ' bcgupce ', ' BCGupcext2 ', ' BCGupcext5 ', ' bcgpostnet ', ' bcgothercode ' *
$codebar = $_request[' Codebar ']; The software supports all encodings by simply adjusting the $codebar parameters.
Including the barcode technology
Include (' class/'. $codebar. ') Barcode.php ');
Loading Font
$font = new Bcgfont ('./class/font/arial.ttf ', 10);
The arguments are R, G, B for color.
$color _black = new Bcgcolor (0, 0, 0);
$color _white = new Bcgcolor (255, 255, 255);
$code = new $codebar ();
$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)
$text = $_request[' text ']; The contents of the barcode to be data
$code->parse ($text);
/* This is the list of the arguments
1-filename (Empty:display on screen)
2-background Color * *
$drawing = new Bcgdrawing (', $color _white);
$drawing->setbarcode ($code);
$drawing->draw ();
Header that says it's an image (remove it if save the barcode to a file)
Header (' content-type:image/png ');
Draw (or save) the image into the PNG format.
$drawing->finish (bcgdrawing::img_format_png);
?>