1, Download Phpqrcode class Library
2, introduction of QRCode Library
I use the TP framework, directly download the QRCode library into the TP framework under the core framework of the vendor file, vendor (' Phpqrcode.phpqrcode '); Introduced
3, code example
Vendor ("Phpqrcode.phpqrcode"); Introducing the Phpqrcode Library
$value = ' http://www.baidu.com '; Two-dimensional code content
容错级别: L(QR_ECLEVEL_L,7%),M(QR_ECLEVEL_M,15%),Q(QR_ECLEVEL_Q,25%),H(QR_ECLEVEL_H,30%);
$errorCorrectionLevel = ' L '; Fault tolerance level
$matrixPointSize = 6;//Generate picture size
$img _name_url = ' qrcode.png ';
\qrcode::p ng ($value, $img _name_url, $errorCorrectionLevel, $matrixPointSize, 2); Generate two-dimensional code image, has now generated a QR code image without logo img_name_url is the generated QR code saved address
$logo = ' logocode.png ';//Ready logo image
$QR = ' qrcode.png ';//has generated the original two-dimensional code map, is generated above the two-dimensional code map, it can also be your own two-dimensional code picture, this is not fixed
if ($logo!== FALSE) {
$QR = imagecreatefromstring (file_get_contents ($QR)); Get QR code picture return True | False
$logo = imagecreatefromstring (file_get_contents ($logo)); Get logo image return True | False
$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/5;
$scale = $logo _width/$logo _qr_width;
$logo _qr_height = $logo _height/$scale;
$from _width = ($QR _width-$logo _qr_width)/2;
Imagecopyresampled ($QR, $logo, $from _width, $from _width, 0, 0, $logo _qr_width, $logo _qr_height, $logo _width, $logo _ height); Regroup and resize pictures
}
Output picture
Header ("Content-type:image/png");
$imgs = './qrcode/qrcodes.png '; Fill in the two-dimensional code image address
Imagepng ($QR, $imgs); Save the generated QR code with logo
Echo $imgs; This is the address with the logo QR code.
PHP uses QRCode to generate two-dimensional code with logo