PHP to generate barcodes second source of the road

Source: Internet
Author: User

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. The interface is shown in the following figure:

1.Type: Select barcode type

2.Output: Picture format for output

3.Thickness: Barcode Height

4.Resolution: Barcode Size

5.Font: The text size below the bar code, you can not display text

6.Text: Contents of Barcode printing

Of course, this program is only the text into the bar code, but not flexible to use it embedded in other PHP programs, I will compress the test.php inside the package

Some adjustments have been made to make it 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:

Effect Chart:

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 ']; The software supports all encodings by simply adjusting 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 (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 ']; The contents 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 the PNG format.
$drawing->finish (bcgdrawing::img_format_png);
?>

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.