PHP uses QRCode to generate two-dimensional code with logo

Source: Internet
Author: User

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

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.