Thinkphp323 Integrated Phpqrcode to create a QR code with logo

Source: Internet
Author: User
Thinkphp does not have a QR code-related library, so we can integrate phpqrcode to achieve the function of generating QR code.

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 to this folder.

Call Phpqrcode to generate two-dimensional code

Add the following method under the Indexcontroller controller:

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 QR code picture        $ Object = new \qrcode ();       $object->png ($url, False, $errorCorrectionLevel, $matrixPointSize, 2);    }

Access:Http://127.0.0.1/Index/qrcode to see the generated QR code.

Create a QR code with logo

Call Phpqrcode to generate a QR code, and then use PHP's image correlation 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 picture size//generate QR code picture qrcode::p ng ($value, ' qrcode.png ', $  Errorcorrectionlevel, $matrixPointSize, 2); $logo = ' logo.png ';///Ready logo image $QR = ' qrcode.png ';//The original two-dimensional code figure already generated if ($logo!== FALSE) {$QR = Imagecreatefromstring (f    Ile_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 $l    Ogo_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, $logo _  width, $logo _height);  }//Output picture imagepng ($QR, ' helloweixin.png '); Echo ';

The above is the whole content of this article, I hope that everyone's learning has helped, but also hope that we support this site.

The above describes the Thinkphp323 integration Phpqrcode generated with the logo of the QR Code, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.