The PHP5 version is used in this article. Be sure to turn on PHP's GD module before use. This is php_gd2.dll in Windows and gd.so in Linux. Extract the compressed file to Apache and execute http://localhost/barcode/index.php. PHP5 generates barcodes as shown below:
1. Type: Select the barcode type
2. Output: output image format
3. Thickness: Barcode height
4. Resolution: barcode size
5. Font: the size of the text below the barcode, or no text displayed
6. Text: The content of barcode printing
Of course, this PHP5 barcode generation program only generates text into barcodes, but it cannot be flexibly embedded into other PHP programs when used. I made some adjustments to test.php in the compressed package so that it can be flexibly used. Other programs. When running, just pass 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:
PHP5 generates barcode renderings:
PHP5 generates barcode test.php code:
// 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]; //For all codes supported by this software, just adjust the $codebar parameter.
// 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]; //PHP5 generates the content of the barcode data
$code->parse($text); /* Here 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 is an image (remove it if you save the barcode to a file)
header(Content-Type: image/png); // Draw (or save) the image into PNG format.
$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
?>