PHP generates two-dimensional code

Source: Internet
Author: User

Using PHP qrcode to generate two-dimensional code;

PHP QRCode official website http://phpqrcode.sourceforge.net/

Download phpqrcode.php on the official website is OK;

Then, see if your PHP environment is turned on GD2, if not, turn on support;

Using the phpqrcode.php function png () method can generate the most basic QR code;

<?php

Include ' phpqrcode.php ';
$value = ' http://www.cnblogs.com/laowenBlog/'; Two-dimensional code content
QRCode::p ng ($value);

?>

In practical application, we should add our own logo in the middle of the QR code. The code is as follows:

<?php

Include ' phpqrcode.php '; Introduction of phpqrcode.php
$value = ' http://www.cnblogs.com/laowenBlog/'; The contents of the QR code to be generated
$errorCorrectionLevel = ' H '; Fault tolerance level
L 7% Loadline can be modified.
Loadline of M 15% can be modified
The loadline of Q 25% can be corrected
Loadline of H 30% can be modified
$matrixPointSize = 10; Generate picture size
$img = "Img.png"; Generate the name of the picture
Generate two-dimensional code images
QRCode::p ng ($value, $img, $errorCorrectionLevel, $matrixPointSize, 3);
The contents of the parameter 12-dimensional code
Parameter 2 generate the name of the two-dimensional code picture
Fault tolerance level for parameter 32 barcode recognition
Parameter 4 the size of the picture that generated the QR code
Parameter 52 dimension around border white space spacing value
$logo = ' logo.png '; Ready logo image
$QR = $img; Original two-dimensional code diagram that has been generated
Determine if the logo exists
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 Picture width
$logo _height = Imagesy ($logo);//logo Picture height
$logo _qr_width = $QR _WIDTH/4;
$scale = $logo _width/$logo _qr_width;
$logo _qr_height = $logo _height/$scale;
$from _width = ($QR _width-$logo _qr_width)/2;
Regroup and resize pictures
Imagecopyresampled ($QR, $logo, $from _width, $from _width, 0, 0, $logo _qr_width, $logo _qr_height, $logo _width, $logo _ height);
}
Output picture
Imagepng ($QR, ' ok.png ');
Echo ' ';
Die ();

?>

Generated as follows:

PHP generates two-dimensional code

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.