Generate one-dimensional code using PHP

Source: Internet
Author: User
Generate a one-dimensional code using PHP. this code is from & nbsp; http://www.nixiaofeng.com/110.html&lt ;? Php $ code = $ _ GET ['code']; if ($ code! = "") {If (! Is_numeric ($ code) die ('input is not a number') generates a one-dimensional code using PHP
This code is from http://www.nixiaofeng.com/110.html
 13) die ('incorrect bar code length'); if (strlen ($ code) = 12) {// calculate the check bit $ lsum = 0; $ rsum = 0; for ($ I = 1; $ I <= strlen ($ code); $ I ++) {if ($ I % 2) {$ lsum + = (int) $ code [$ i-1];} else {$ rsum + = (int) $ code [$ i-1];} $ tsum = $ lsum + $ rsum * 3; $ chkdig = 10-($ tsum % 10); if ($ chkdig = 10) $ chkdig = 0; $ code. = $ chkdig;} // start of Definition $ start = '000000'; // define the abort operator $ end = '000000 '; // define the intermediate separator $ center = '20140901'; // define the left data code $ Guide = array (0 => 'aaaaa', 'ababab', 'aabbab ', 'aabbba ', 'ababab', 'abbaab', 'abbbaa', 'ababab', 'ababba', and 'abbaba'); // defines the left-side code, there are two types: "A" and "B": $ Lencode = array ("A" => array ('123456', '123456', '1234568 ', '123', '123', '123', '123', '123', '123'), "B" => array ('123', '123 ', '123', '123', '123', '123', '123', '123', '123', '123'); // define the right code, unified as "C" encoding $ Rencode = array ('20160301', '20160301', '20160301', '20160301', '20160301', '20160301 ', '20140901', '20160901', '20160901'); // encoding start code $ barcode = $ start; // Encode the left data bit for ($ I = 1; $ I <= 6; $ I ++) {$ barcode. = $ Lencode [$ Guide [$ code [0] [($ i-1)] [$ code [$ I];} // Encode the intermediate separator $ barcode. = $ center; // Encode the right data bit for ($ I = 7; $ I <13; $ I ++) {$ barcode. = $ Rencode [$ code [($ I)];} // code abort $ barcode. = $ end; // defines the width and height of each bar code unit, in pixels $ width = 2; $ height = 40; // defines the height increment of the start operator, stop operator, and intermediate separator $ increment = 10; // creates a square (× 95 is because the entire bar code contains 95 units, + 60 and + 30 are left blank borders around the bar code Image) $ img = ImageCreate ($ width * 95 + 60, $ height + 30 ); // currently, this square is transparent // "1" color (black) and "0" color (white) $ fg = ImageColorAllocate ($ img, 0, 0, 0); $ bg = ImageColorAllocate ($ img, 255,255,255); // fill the entire square ImageFilledRectangle ($ img, 0, 0, $ width * 95 + 60, $ height + 30, $ bg); // output the bar code Image for ($ x = 0; $ x
 
  
= 92) for the abort operator ($ x >=45 & $ x <50) for the intermediate separator // these three must be added to the if ($ x <4) | ($ x >=45 & $ x <50) | ($ x >=92) {$ increment = 10;} else {$ increment = 0 ;} // when the encoding value is "1", the output is black. when the encoding value is "0", the output is White if ($ barcode [$ x] = '1 ') {$ color = $ fg;} else {$ color = $ bg;} ImageFilledRectangle ($ img, ($ x * $ width) + 30, 5, ($ x + 1) * $ width + 29, $ height + $ increment, $ color);} ImageString ($ img, 5, 20, $ height + 5, $ code [0], $ fg); for ($ x = 0; $ x <6; $ x ++ ) {// Left-side ID: ImageString ($ img, 5, $ width * (8 + $ x * 6) + 30, $ height + 5, $ code [$ x + 1], $ fg); // ImageString ($ img, 5, $ width * (53 + $ x * 6) + 30, $ height + 5, $ code [$ x + 7], $ fg);} header ("Content-Type: image/jpeg"); ImageJPEG ($ img ,"", 100) ;}?>
 


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.