PHP generates a QR code and uses the PHPQRCode QR code to generate a class library.

Source: Internet
Author: User
The php qr code generation example is generated using the PHPQRCode class library. with this example, we can generate a QR code as easily as echoa. here we will introduce it to you. in the past, Google provided a relatively complete interface for generating QR code... the php qr Code generation example is generated using the php qr Code class library. with this example, we can generate a QR Code as simple as echo a. Let's introduce it to you.

In the past, Google provided a relatively complete interface for generating QR codes, which is easy to call. However, due to problems with accessing google, other methods are required to generate QR codes.

Php qr Code is a php qr Code generation class library that allows you to easily generate QR codes. the official website provides download and multiple demo demos.

Address: http://phpqrcode.sourceforge.net

After downloading the class library provided on the official website, you only need to use phpqrcode. php to generate a QR code. of course, you must enable GD2.

Qrlib. php is a full version of the official call instance. the code is as follows:

QRcode: png ('code data text', 'filename.png '); // creates file

QRcode: png ('Some othertext 1234 '); // creates code image and outputs it directly into browser

Phpqrcode. php is a merged version with only one file, but the generation speed is slow and inaccurate.

Phpqrcode. php provides a key png () method. the code is as follows:

Public static function png ($ text, $ outfile = false, $ level = QR_ECLEVEL_L, $ size = 3, $ margin = 4,

$ Saveandprint = false)

{

$ Enc = QRencode: factory ($ level, $ size, $ margin );

Return $ enc-> encodePNG ($ text, $ outfile, $ saveandprint = false );

}

The parameter $ text indicates that two pieces of information text are generated. the parameter $ outfile indicates whether to output the two-dimensional code image file. the default value is no. the parameter $ level indicates the coverage rate, that is, the coverage area can also be identified, the values are L (QR_ECLEVEL_L, 7%), M (QR_ECLEVEL_M, 15%), Q (QR_ECLEVEL_Q, 25%), H (QR_ECLEVEL_H, 30%), and the parameter $ size indicates the image size, the default value is 3. the parameter $ margin indicates the gap between blank areas in the border around the QR code. the default value is 4. the parameter $ saveandprint indicates whether to save and display the QR code. by default, the parameter is not saved.

Include 'phpqrcode. php'; QRcode: png ('http: // mingzi.phprm.com '); the above code outputs a two-dimensional diagram.

In actual application, we will add our own LOGO in the middle of the QR Code to enhance the promotion effect. First, we will use the php qr Code to generate a QR Code image and then use the php image function, add the prepared logo image to the middle of the generated original QR code image, and then generate a new QR code image. of course, it is better to select the renewal rate H at this time. the code is as follows:

 

// Output image

imagepng($QR, 'myxzy.png');  echo '';

Now we have generated the QR code image we want. we will not introduce it today due to limited time. next time we will introduce an address that uses it to generate the wap version of the website.


Address:

Reprinted at will, but please attach the article address :-)

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.