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

Source: Internet
Author: User

========================================================== ======= 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.
 

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.