PHP uses the QR code library to generate a two-dimensional code with a logo image

Source: Internet
Author: User
Tags php class

These days of the project to use to generate two-dimensional code, and the boss asked for a logo in the middle of the two-dimensional code, the past is the generation of the standard, that is, a more pure two-dimensional code, now the boss of this request, a moment let me no clue, but after efforts to find information, found PHP has a class library called QRCode, use it to generate this two-dimensional code is very convenient, so the study, finally fix, the following code to share to everyone. Let's take a look at the resulting effect:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6F/22/wKiom1WSaH-xLoaiAACNAdVEtsU741.jpg "title=" Ewmlogo.png "alt=" Wkiom1wsah-xloaiaacnadvetsu741.jpg "/>

Specific PHP code, first call phpqrcode.php, and then look at the comments in the code, and then www.codesc.net this URL to your own, as well as logo images replaced by you, and then modify the other parameters can be:

<?phpinclude  (' phpqrcode.php '); $value  =  ' http://www.codesc.net ';//QR code data $errorcorrectionlevel  =  ' l ';//Error correction level: L, M, Q, h$matrixpointsize = 10;//Two-dimensional code point size: 1 to 10QRcode::p ng  (  $value,   ' ewm.png ',  $errorCorrectionLevel,  $matrixPointSize, 2 );//file name without logo qr code echo  " QR code has been generated " . " <br /> "; $logo  =  ' emwlogo.gif ';//need to display the logo image in the QR Code $qr =  ' Ewm.png ';if  ($logo  !== false)  {     $QR  =  imagecreatefromstring  ( file_get_contents  (  $QR  )  )     $ logo = imagecreatefromstring  ( file_get_contents  (  $logo  )  );      $QR _width = imagesx  (  $QR  );     $QR _height  = imagesy  (  $QR  );     $logo _width = imagesx  (   $logo  );     $logo _height = imagesy  (  $logo  );     $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 );} imagepng  (  $QR,  ' ewmlogo.png '  );//file name with logo qr code?>

The Phpqrcode.php class library can be downloaded here: http://sourceforge.net/projects/phpqrcode/

PHP uses the QR code library to generate a two-dimensional code with a logo image

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.