The PHP5 instance tutorial is simple to generate a barcode

Source: Internet
Author: User
This document uses the PHP5 version. 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. This document uses the PHP5 version. 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:Barcode size

5.Font:The text size below the bar code is not displayed

6. Text: bar code printed content

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:

PHP5 generates a barcode:

PHP5 generates the code test. php:

    // Including all required classes Require('Class/BCGFont. php ');
  1. Require('Class/BCGColor. php ');Require('Class/BCGDrawing. php ');
  2. /* 'Bcgcodabar ', 'bcgcode11', 'bcgcode39extended', 'bcgcode93', 'bcgcode128', 'bcgean8', 'bcgean13', 'bcgisbn ', 'bcgi25', 'bcgs25', 'bcgmsi ',
  3. 'Bcgupca ', 'bcgupce', 'bcgupcext2', 'bcgupcext5', 'bcgpostnet', 'bcgothercode' */$ codebar = $ _ REQUEST ['codebar']; // All codes supported by the software. you only need to adjust the $ codebar parameter.
  4. // Including the barcode technologyInclude('Class/'. $ codebar.'. barcode. php ');
  5. // Loading Font $ font =NewBCGFont ('./class/font/Arial. ttf', 10 );
  6. // The arguments are R, G, B for color. $ color_black =NewBCGColor (0, 0, 0 );
  7. $ Color_white =NewBCGColor (255,255,255); $ code =New$ Codebar ();
  8. $ Code-> setScale (2); // Resolution $ code-> setThickness (30); // Thickness
  9. $ Code-> setForegroundColor ($ color_black); // Color of bars $ code-> setBackgroundColor ($ color_white); // Color of spaces
  10. $ Code-> setFont ($ font); // Font (or 0) $ text = $ _ REQUEST ['text']; // PHP5 generates the content of the barcode to be data
  11. $ Code-> parse ($ text);/* Here is the list of the arguments
  12. 1-Filename (empty: display on screen) 2-Background color */
  13. $ Drawing =NewBCGDrawing ('', $ color_white); $ drawing-> setBarcode ($ code );
  14. $ Drawing-> draw (); // Header that says it is an image (remove it if you save the barcode to a file)
  15. Header ('content-Type: image/png '); // Draw (or save) the image into PNG format.
  16. $ Drawing-> finish (BCGDrawing: IMG_FORMAT_PNG );
  17. ?>

PHP source code download

Http://www.bitscn.com/upimg/soft/201003/1_16030353.zip

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.