Php qr code generation method (googleAPi, PHP class library, libqrencode, etc)

Source: Internet
Author: User
PHP Method 1: Use google open API to complete [php] $ urlToEncode & quot; name: Liu Xinming, phone: 18792448443 & quot; generateQRfro... SyntaxHighlighter. all ();

========================================================== ======= PHP Usage ====================================== ==============================
1. use google to open APIs
[Php]
$ UrlToEncode = "name: Liu Xinming, phone: 18792448443 ";
GenerateQRfromGoogle ($ urlToEncode );
/**
* Google api QR code generation [QRcode can store any text of a maximum of 4296 letters/numbers. for details, see the QR code data format]
* @ Param string $ information contained in the chlorophyll QR code, which can be numbers, characters, binary information, and Chinese characters. The data type cannot be mixed and must pass through the UTF-8 URL-encoded. if the information to be passed exceeds 2 K bytes, use the POST method
* @ Param int $ widhtHeight: set the size of the generated QR code
* @ Param string $ EC_level: the error correction level is optional. the QR code supports four levels of error correction, which is used to restore lost, read, fuzzy, and data.
* L-default: 7% of lost data can be identified.
* M-identifies 15% of data loss
* Q-identifies 25% of data loss
* H-identifies 30% of data loss
* @ Param int $ the distance between the QR code generated by margin and the image border
*/
Function generateQRfromGoogle ($ chlorophyll, $ widhtHeight = '000000', $ EC_level = 'l', $ margin = '0 ')
{
$ Chlorophyll = urlencode ($ chlorophyll );
Echo '';
}


More detailed can see Baidu Library: http://wenku.baidu.com/view/b2a6ffc60c22590102029dae.html

2. php QR Code Library
Php qr Code is open source (LGPL) library for generating QR Code,
2-dimen1_barcode. Based on libqrencode C library,
Provides API for creating QR Code barcode images (PNG, JPEG thanks to GD2 ).
Implemented purely in PHP, with no external dependencies (effect GD2 if needed ).
PS: due to the time relationship, I only tested the open API of google. Others can be tested by themselves.
========================================================== ========================================== ======================================
A two-dimensional bar code (2-dimen1_bar code) records data in a certain area of the plane based on a specific geometric pattern.
Commonly used Code systems include Data Matrix, Maxi Code, Aztec, QR Code, response Code, limit 417, Ultracode, Code 49, and Code 16K.
①: Stacked/row-arranged two-dimensional bar codes, such as Code 16 K, Code 49, and Code 417 (such ).

②: Matrix qr code is the most popular one.
The two-dimensional code stores a larger amount of data. it can contain numbers, characters, Chinese text, and other mixed content. it has a certain degree of fault tolerance (it can be read normally after some damages). It has a high space utilization rate.
③: Introduction to QR CODE

For example, the basic structure of a qrcode, where:
Location detection image, location detection Image separator, and positioning Image: used to locate the QR code. for each QR code, the location is fixed, but the size and specifications may vary;
Calibration image: the specification is determined, and the quantity and position of the correction image are also determined;
Format information: indicates the error correction level for modifying the QR code, which can be L, M, Q, and H;

Version Information: the type of the QR code. There are 40 types of matrix (generally black and white), from 21x21 (version 1 ), to 177x177 (version 40), each version adds four modules to each side of the previous version.
Data and error correction code: the information of the actually saved QR code, and the error code (used to correct the error caused by damage to the QR code ).

Brief encoding process:
1. data Analysis: determines the encoding character type and converts it to a symbolic character based on the corresponding character set. If an error correction level is selected, the higher the error correction level, the smaller the actual data capacity.

2. Data encoding: converts a data character into a bitstream. each 8-bit code word represents a code word sequence of data. In fact, the data content of the QR code is known as the data code sequence.

 

 
 
Data can be encoded in one mode for more efficient decoding. for example, for data: 01234567 encoding (version 1-H ),
1) group: 012 345 67
2) convert to binary: 012 → 0000001100
345 → 0101011001
67 → 1000011
3) conversion sequence: 0000001100 0101011001 1000011
4) convert the number of characters to binary: 8 to 0000001000
5) add the mode indicator (number) 000:0001 0000001000 0000001100 0101011001 1000011
For letters, Chinese characters, and Japanese, only the group mode and mode are different. The basic methods are the same.

3. error correction code: blocks the above code sequence as needed, generates error correction codes based on the error correction level and the code segment, and adds the error correction code to the data code sequence, become a new sequence.

 
When the two-dimensional code specifications and error correction levels are determined, the total number of characters that can be accommodated by the two-dimensional code and the number of characters in the error correction code are also determined. for example, in version 10, when the error correction level is H, A total of 346 code words are supported, including 224 error correction code words.
That is to say, about 1/3 of the code in the QR code area is redundant. For these 224 error codes, it can correct 112 replacement errors (such as black and white inversion) or 224 data read errors (unreadable or undecoded ),
The error correction capacity is 112/346 = 32.4%.

4. construct the final data information: place the sequence generated above in order, as shown in a chunk, when the specification is determined.
Data is segmented according to regulations, and each block is calculated to obtain the corresponding block of the error correction code. the block of the error correction code form a sequence in order and is added to the back of the original data code sequence.
For example, D1, D12, D23, D35, D2, D13, D24, D36 ,... d11, D22, D33, D45, D34, D46, E1, E23, E45, E67, E2, E24, E46, E68 ,...

Constructor: puts the probe image, separator, positioning image, correction image, and code module into the matrix.

 

Fill in the complete sequence above to the area of the QR code matrix of the corresponding specification.


6. masking: The masking image is used in the encoding area of the symbol, so that the dark and light (black and white) areas in the QR code image can be evenly distributed.
An algorithm. if you are interested, you can continue.
7. Format and version information: Enter the format and version information in the corresponding region.
Both versions 7-40 contain version information, and all versions without version information are 0. The two locations on the QR code contain version information, which is redundant.
The version information is 18 bits in total, with a 6x3 matrix. The data in six bits is, for example, version 8, the data bit information is 001000, and the next 12 bits are error correction bits.
 

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.