Php uses php qr Code to generate a QR Code (with logo)

Source: Internet
Author: User

We need to use some class libraries to generate two-dimensional codes. The following describes how to generate two-dimensional codes using php qr codes. The generation method is very simple. I will introduce it below.

Php QR Code library is used for implementation. No additional PHP extension is required.
First, download the class library package. Sometimes the address cannot be opened.
Address: http://phpqrcode.sourceforge.net/
Download: http://sourceforge.net/projects/phpqrcode/

The phpqrcode. php file is generally introduced for use.

Examples

Direct browser output:

The Code is as follows: Copy code

<? Php
Include "phpqrcode/phpqrcode. php ";
$ Value = "http://www.hzhuti.com ";
$ ErrorCorrectionLevel = "L ";
$ MatrixPointSize = "4 ";
QRcode: png ($ value, false, $ errorCorrectionLevel, $ matrixPointSize );
Exit;
?>

Image File output

The Code is as follows: Copy code

<? Php

// File output
Include ('phpqrcode/phpqrcode. php ');

// QR code data
$ Data = 'HTTP: // www. bKjia. c0m ';

// Generated file name
$ Filename = '1111.png ';

// Error Correction level: L, M, Q, H
$ ErrorCorrectionLevel = 'l ';

// Vertex size: 1 to 10
$ MatrixPointSize = 4;
QRcode: png ($ data, $ filename, $ errorCorrectionLevel, $ matrixPointSize, 2 );
?>

Generate a QR code with a central logo

The Code is as follows: Copy code

<? Php

// Generate a QR code with a central logo
Include ('phpqrcode/phpqrcode. php ');
$ Value = 'HTTP: // www. bKjia. c0m ';
$ ErrorCorrectionLevel = 'l ';
$ MatrixPointSize = 10;
QRcode: png ($ value, 'xiangyang.png ', $ errorCorrectionLevel, $ matrixPointSize, 2 );
Echo "QR code generated". "<br/> ";
$ Logo = 'bdlogo.gif ';
$ QR = 'xiangyang.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,'xiangyanglog.png ');
?>

Related Article

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.