PHP5 instance Tutorial: generate a barcode simply _ PHP Tutorial

Source: Internet
Author: User
The PHP5 instance tutorial simply generates a barcode. 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 the PHP5 version 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

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 );

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]; // you only need to adjust the $ codebar parameter for all codes supported by the software.

// 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 to be 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 );

?>

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. Decompress the compressed file to Apache and execute http: // l...

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.