Thinkphp3.2.3 integrate phpqrcode to generate QR code with logo and qrcode QR code logo

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.