Thinkphp3.2.3 integrate phpqrcode to generate QR code with logo and qrcode QR code logo
Thinkphp does not contain libraries related to QR codes. Therefore, we can integrate phpqrcode to generate QR codes.
Download phpqrcode
: Http://phpqrcode.sourceforge.net/
Integrate into Thinkphp framework
Create the phpqrcode directory under "ThinkPHP \ Library \ Vendor \" and decompress the compressed package to this folder.
Call phpqrcode to generate a QR code
Add the following method to the IndexController:
Public function qrcode ($ url = "www.baidu.com", $ level = 3, $ size = 4) {Vendor ('phpqrcode. phpqrcode'); $ errorCorrectionLevel = intval ($ level); // fault tolerance level $ matrixPointSize = intval ($ size ); // generate image size // generate a QR code image $ object = new \ QRcode (); $ object-> png ($ url, false, $ errorCorrectionLevel, $ matrixPointSize, 2 );}
Visit http: // 127.0.0.1/Index/qrcode to view the generated QR code.
Generate a QR code with a logo
Call phpqrcode to generate a QR code, and then use the php image function to add the logo image to the generated QR code image.
Include 'phpqrcode. php '; $ value = 'HTTP: // www.cnblogs.com/txw1958/'; // QR code content $ errorCorrectionLevel = 'l'; // fault tolerance level $ matrixPointSize = 6; // generate image size // generate QR code image QRcode: png ($ value, 'qrcode.png ', $ errorCorrectionLevel, $ matrixPointSize, 2); $ logo = 'logo.png '; // The prepared logo image $ QR = 'qrcode.png '; // The generated original QR code image 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 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 the image and resize imagecopyresampled ($ QR, $ logo, $ from_width, $ from_width, 0, 0, $ logo_qr_width, $ logo_qr_height, $ logo_width, $ logo_height);} // output image imagepng ($ QR, 'helloweixin.png '); echo ' ';
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.