Using PHP qrcode to generate two-dimensional code;
PHP QRCode official website http://phpqrcode.sourceforge.net/
Download phpqrcode.php on the official website is OK;
Then, see if your PHP environment is turned on GD2, if not, turn on support;
Using the phpqrcode.php function png () method can generate the most basic QR code;
<?php
Include ' phpqrcode.php ';
$value = ' http://www.cnblogs.com/laowenBlog/'; Two-dimensional code content
QRCode::p ng ($value);
?>
In practical application, we should add our own logo in the middle of the QR code. The code is as follows:
<?php
Include ' phpqrcode.php '; Introduction of phpqrcode.php
$value = ' http://www.cnblogs.com/laowenBlog/'; The contents of the QR code to be generated
$errorCorrectionLevel = ' H '; Fault tolerance level
L 7% Loadline can be modified.
Loadline of M 15% can be modified
The loadline of Q 25% can be corrected
Loadline of H 30% can be modified
$matrixPointSize = 10; Generate picture size
$img = "Img.png"; Generate the name of the picture
Generate two-dimensional code images
QRCode::p ng ($value, $img, $errorCorrectionLevel, $matrixPointSize, 3);
The contents of the parameter 12-dimensional code
Parameter 2 generate the name of the two-dimensional code picture
Fault tolerance level for parameter 32 barcode recognition
Parameter 4 the size of the picture that generated the QR code
Parameter 52 dimension around border white space spacing value
$logo = ' logo.png '; Ready logo image
$QR = $img; Original two-dimensional code diagram that has been generated
Determine if the logo exists
if ($logo!== FALSE) {
$QR = imagecreatefromstring (file_get_contents ($QR));
$logo = imagecreatefromstring (file_get_contents ($logo));
$QR _width = Imagesx ($QR);//QR code image width
$QR _height = Imagesy ($QR);//QR code image Height
$logo _width = Imagesx ($logo);//logo Picture width
$logo _height = Imagesy ($logo);//logo Picture height
$logo _qr_width = $QR _WIDTH/4;
$scale = $logo _width/$logo _qr_width;
$logo _qr_height = $logo _height/$scale;
$from _width = ($QR _width-$logo _qr_width)/2;
Regroup and resize pictures
Imagecopyresampled ($QR, $logo, $from _width, $from _width, 0, 0, $logo _qr_width, $logo _qr_height, $logo _width, $logo _ height);
}
Output picture
Imagepng ($QR, ' ok.png ');
Echo ' ';
Die ();
?>
Generated as follows:
PHP generates two-dimensional code