There are no two-dimensional code-related libraries in the thinkphp, so we can complete the function of generating two-dimensional code by consolidating phpqrcode.
Download Phpqrcode
Download Address: HTtp://phpqrcode.sourceforge.net/
Integration into the thinkphp framework
Under Thinkphp\library\vendor\, create a new directory Phpqrcode to extract the contents of the compressed package into the folder.
Call Phpqrcode to generate a two-dimensional code
Under the Indexcontroller controller, add the following methods:
Public Function QRCode ($url = "www.baidu.com", $level =3, $size =4)
{
vendor (' Phpqrcode.phpqrcode ');
$errorCorrectionLevel =intval ($level);//Fault tolerance level
$matrixPointSize = Intval ($size);//Generate picture size
//Generate two-dimensional code picture
$ Object = new \qrcode ();
$object->png ($url, False, $errorCorrectionLevel, $matrixPointSize, 2);
}
Access:Http://127.0.0.1/Index/qrcode can see the generated two-dimensional code.
Generate a two-dimensional code with logo
Call Phpqrcode to generate a two-dimensional code, and then use the PHP image correlation function to add the logo image to the generated two-dimensional code picture.
Include ' phpqrcode.php '; $value = ' http://www.cnblogs.com/txw1958/'; Two-dimensional code content $errorCorrectionLevel = ' L ';//fault tolerance level $matrixPointSize = 6;//Generate picture size//Generate two-dimensional code picture QRCode::p ng ($value, ' qrcode.png
', $errorCorrectionLevel, $matrixPointSize, 2); $logo = ' logo.png '; the prepared logo picture $QR = ' qrcode.png ';//The original two-dimensional code graph if ($logo!== FALSE) {$QR = Imagecreatefromstri
Ng (file_get_contents ($QR));
$logo = imagecreatefromstring (file_get_contents ($logo));
$QR _width = Imagesx ($QR);//Two-dimensional code picture width $QR _height = Imagesy ($QR);//two-dimensional code picture height $logo _width = imagesx ($logo);//logo Picture width
$logo _height = Imagesy ($logo);//logo picture 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; Regroup pictures and resize imagecopyresampled ($QR, $logo, $from _width, $from _width, 0, 0, $logo _qr_width, $logo _qr_height, $log
O_width, $logo _height);
///Output Picture imagepng ($QR, ' helloweixin.png '); Echo ' ';
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.