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, you need to use other methods 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 in your PHP environment. ''
Qrlib. php is the full version. The official call example:
| The code is as follows: |
Copy code |
|
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. Usage:
Phpqrcode. php provides a key png () method.
| The code is as follows: |
Copy code |
|
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 renewal rate, that is, the covered areas can also be identified, namely, L (QR_ECLEVEL_L, 7%), M (QR_ECLEVEL_M, 15%), Q (QR_ECLEVEL_Q, 25%), H (QR_ECLEVEL_H, 30%); parameter $ size indicates the size of the generated image. The default value is 3. 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 the QR code and display it. By default, it is not saved.
Include 'phpqrcode. Php ';
QRcode: png ('http: // mingzi.111cn.net '); the above code outputs a two-dimensional diagram. |
In practice, we will add our own LOGO in the middle of the QR code to enhance the promotion effect. First, use the php qr Code to generate a QR Code image, and then use the php image function to add the prepared logo image to the middle of the generated original QR Code image, 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: |
Copy code |
<? Php
Include 'phpqrcode. Php ';
$ Value = 'http: // www.111cn.net '; // QR code content
$ Qr_eclevel = 'h'; // fault tolerance level
$ Picsize = 6; // generate the image size
QRcode: png ($ value, 'qrcode.png ', $ qr_eclevel, $ picsize); // Generate a QR code image
$ Logo = 'logo.png '; // prepared logo image
$ QR = 'qrcode.png '; // generated original QR code
If ($ logo! = FALSE ){
$ QR = imagecreatefromstring (file_get_contents ($ QR ));
$ Logo = imagecreatefromstring (file_get_contents ($ logo ));
$ QR_width = imagesx ($ QR); // the image width of the QR code.
$ QR_height = imagesy ($ QR); // The Image height of the QR code.
$ Logo_width = imagesx ($ logo); // logo image width
$ Logo_height = imagesy ($ logo); // logo image height
$ Logo_qr_width = $ QR_width/5;
$ Scale = $ logo_width/$ logo_qr_width;
$ Logo_qr_height = $ logo_height/$ scale;
$ From_width = ($ QR_width-$ logo_qr_width)/2;
// Re-combine and resize the image
Imagecopyresampled ($ QR, $ logo, $ from_width, $ from_width, 0, 0, $ logo_qr_width,
$ Logo_qr_height, $ logo_width, $ logo_height );
}
// 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.