Php code generation-PHP Tutorial

Source: Internet
Author: User
Php generates the barcode code. Php generates a barcode code to generate an image. in php, you must use the gd library to generate an image. in the INI file, find extension php and generate the barcode code to generate an image. in php, we must use the gd library to generate an image. Therefore, you must find your php. in the INI file, find extension = php_gd2.dll and remove the previous one ;. You may use some instances.

Php tutorials generate barcode code
/*
To generate a barcode, you must generate an image. to generate an image in php, you must use the gd Library. Therefore, you must find the extension = php_gd2.dll file to remove the previous one;
. You may use some instances.
*/

Class cd_barra
{
Var $ file;
Var $;

Var $ cd_barras = array (0 => "00110", 1 => "10001", 2 => "01001", 3 => "11000 ", 4 => "00101 ",
5 => "10100", 6 => "01100", 7 => "00011", 8 => "10010", 9 => "01010"
);
Function cd_barra ($ value, $ files, $ into = 1 ){
$ Lower = 1; $ hight = 55;
$ This-> into = $;
For ($ count1 = 9; $ count1> = 0; $ count1 --){
For ($ count2 = 9; $ count2> = 0; $ count2 --){
$ Count = ($ count1 * 10) + $ count2;
$ Text = "";
For ($ I = 1; $ I <6; $ I ++ ){
$ Text. = substr ($ this-> cd_barras [$ count1], ($ i-1), 1 ). substr ($ this-> cd_barras [$ count2], ($ i-1), 1 );
}
$ This-> cd_barras [$ count] = $ text;
}
}

// $ Img = imagecreate ($ lower * 95 + 300, $ hight + 30 );
$ Img = imagecreate (145, 55 );

// $ Img = imagecreate (395, 73 );
$ Cl_black = imagecolorallocate ($ img, 0, 0 );
$ Cl_white = imagecolorallocate ($ img, 255,255,255 );



Imagefilledrectangle ($ img, 0, 0, $ lower * 95 + 1000, $ hight + 30, $ cl_white );


Imagefilledrectangle ($ img, 1, 1, 53, $ cl_black );
Imagefilledrectangle ($ img, 2,1, 2,53, $ cl_white );
Imagefilledrectangle ($ img, 3,1, 3,53, $ cl_black );
Imagefilledrectangle ($ img, 4,1, 4,53, $ cl_white );



$ Thin = 1;
If (substr_count (strtoupper ($ _ server ['server _ soft']), "win32 ")){
// O tamanho para windows tem que ser 3
// For windows, the wide bar has = 3
$ Wide = 3;
} Else {
$ Wide = 2.72;
}
$ Pos = 5;
$ Text = $ value;
If (strlen ($ text) % 2) <> 0 ){
$ Text = "0". $ text;
}


While (strlen ($ text)> 0 ){
$ I = round ($ this-> barra_left ($ text, 2 ));
$ Text = $ this-> barra_right ($ text, strlen ($ text)-2 );

$ F = $ this-> cd_barras [$ I];

For ($ I = 1; $ I <11; $ I + = 2 ){
If (substr ($ f, ($ i-1), 1) = "0 "){
$ F1 = $ thin;
} Else {
$ F1 = $ wide;
}


Imagefilledrectangle ($ img, $ pos, 1, $ pos-1 + $ f1, 53, $ cl_black );
$ Pos = $ pos + $ f1;

If (substr ($ f, $ I, 1) = "0 "){
$ F2 = $ thin;
} Else {
$ F2 = $ wide;
}

Imagefilledrectangle ($ img, $ pos, 1, $ pos-1 + $ f2, 53, $ cl_white );
$ Pos = $ pos + $ f2;
}
}


Imagefilledrectangle ($ img, $ pos, 1, $ pos-1 + $ wide, 53, $ cl_black );
$ Pos = $ pos + $ wide;

Imagefilledrectangle ($ img, $ pos, 1, $ pos-1 + $ thin, 53, $ cl_white );
$ Pos = $ pos + $ thin;


Imagefilledrectangle ($ img, $ pos, 1, $ pos-1 + $ thin, 53, $ cl_black );
$ Pos = $ pos + $ thin;

$ This-> put_img ($ img, $ files );
}

Function barra_left ($ input, $ comp ){
Return substr ($ input, 0, $ comp );
}

Function barra_right ($ input, $ comp ){
Return substr ($ input, strlen ($ input)-$ comp, $ comp );
}

Function put_img ($ image, $ file ){
If ($ this-> ){
Imagegif ($ image, $ file );
}
Else {
Header ("content-type: image/gif ");
Imagegif ($ image );
}
Imagedestroy ($ image );
}
}

?>

// Call method

Include ("codes. php ");
$ New_code = new cd_barra ("1234567890", "a.gif", 1 );

?>

...

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.