A simple example of generating a barcode in PHP5. This software supports two versions: PHP4 and PHP5. the PHP5 version is used in this article. Before using the function, you must enable the GD module of PHP. In Windows, it is php_gd2.dll, and in Linux it is gd. so. The software supports PHP4 and PHP5 versions. the PHP5 version is used in this article. Before using the function, you must enable the GD module of PHP. In Windows, it is php_gd2.dll, and in Linux it is gd. so. Decompress the compressed file to Apache and execute Http: // localhost/barcode/index. php. For more information about generating the PHP5 barcode, see:
1. Type: Select the barcode Type
2. Output: Output Image format
3. Thickness: bar code height
4. Resolution: bar code size
5. Font: the text at the bottom of the bar code cannot be displayed.
6. Text: bar code printed content
498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = bar code effect src = "http://www.bkjia.com/uploadfile/2013/0904/20130904094617982.jpg" width = 615 height = 557>
Of course, this PHP5 generated barcode program only generates text as a barcode, but it cannot be flexibly embedded into other PHP programs during use. I will compress the test in the package. php has made some adjustments so that it can be used flexibly in other programs. You only need to pass the barcode type and text to test. php at runtime, for example:
Http: // localhost/barcode/test. php? Codebar = BCGcode39 & text = 20090729
Or run http: // localhost/barcode/mytest. php
Mytest. php code:
- <img src="test.php?codebar=BCGcode39&text=20090729">
PHP5 generates a barcode:
498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = run instance src = "http://www.bkjia.com/uploadfile/2013/0904/20130904094617379.jpg" width = 665 height = 186>
PHP5 generates the code test. php:
-
- // Including all required classes
- Require('Class/BCGFont. php');
- Require('Class/BCGColor. php');
- Require('Class/BCGDrawing. php');
- /* 'Bcgcodabar ', 'bcgcode11', 'bcgcode39extended', 'bcgcode93 ',
- 'Bcgcode128 ', 'bcgean8', 'bcgean13', 'bcgisbn', 'bcgi25', 'bcgs25', 'bcgmsi ',
- 'Bcgupca ', 'bcgupce', 'bcgupcext2', 'bcgupcext5', 'bcgpostnet', 'bcgothercode '*/
- $ Codebar=$ _ REQUEST['Codebar'];// All codes supported by the software. you only need to adjust the $ codebar parameter.
- // Including the barcode technology
- Include('Class /'.$ Codebar.'. Barcode. php');
- // Loading Font
- $ Font=NewBCGFont ('./Class/font/Arial. ttf', 10 );
- // The arguments are R, G, B for color.
- $ Color_black=NewBCGColor (0, 0, 0 );
- $ Color_white=NewBCGColor (1, 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 to be data
- $ Code-> Parse ($ Text);
- /* Here is the list of the arguments
- 1-Filename (empty: display on screen)
- 2-Background color */
- $ Drawing=NewBCGDrawing ('',$ 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 );
- ?>
An exception occurs during running ";
Throw $ e; // throwing an exception
}
}
? >
Bytes. Before using the function, you must enable the GD module of PHP. In Windows, it is php_gd2.dll, and in Linux it is gd. so. Compress...