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. PHP5 generate barcodes See the following figure:
1. Type: Select barcode type
2. Output: Picture format
3. Thickness: Bar code height
4. Resolution: Barcode Size
5. Font: Bar code below the text size, you can not display text
6. Text: Barcode Printing Content
Of course, this PHP5 generated barcode program just to make the text into a barcode, but not flexible to use it embedded in other PHP programs, I will compress the inside of the test.php made some adjustments, so that it can be 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:
- src="test.php?codebar=bcgcode39&text=20090729">
PHP5 Generate Barcode Effect chart:
PHP5 Generate barcode 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 ']; //All coding supported by the software, simply adjust 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 (a); //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 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 PNG format.
- $drawing ->finish (bcgdrawing::img_format_png);
- ?>
An exception occurred during the run;
Throw $e; Throw the exception again
}
}
? ﹥