PHP5 example tutorial simply generate a barcode _php tutorial

Source: Internet
Author: User
The version of PHP5 is used in this article. Before using, be careful to turn on the GD module of PHP. In Windows, gd.so is in Php_gd2.dll,linux. Extract the compressed files to Apache and execute the http://localhost/barcode/index.php. PHP5 Generate barcodes See:

1. Type: Select the barcode type

2. Output: Picture format of the outputs

3. Thickness: Bar code height

4. Resolution: Barcode Size

5. Font: Text size below the barcode, or text not displayed

  

6. Text: Barcode Printing content

Of course, this PHP5 generated barcode program just make the text into a barcode, but the use of it can not be flexibly embedded in other PHP programs, I will compress the package inside the test.php made some adjustments, so that it can be used flexibly 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:

  

PHP5 Generate Barcodes:

  

PHP5 Generate 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]; All encodings supported by the software can only be adjusted with the $codebar parameter.

Including the barcode technology include (class/. $codebar. barcode.php);

Loading Font $font = new Bcgfont (./class/font/arial.ttf, 10);

The arguments is 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 generate barcodes the contents of the data will be

$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's 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);

?>

http://www.bkjia.com/PHPjc/486425.html www.bkjia.com true http://www.bkjia.com/PHPjc/486425.html techarticle The version of PHP5 is used in this article. Before using, be careful to turn on the GD module of PHP. In Windows, gd.so is in Php_gd2.dll,linux. Extract compressed files to Apache, execute http://l ...

  • Related Article

    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.