Home  >  Article  >  Backend Development  >  php uses PHP QR Code to generate QR code (with logo)_PHP tutorial

php uses PHP QR Code to generate QR code (with logo)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:44:00915browse

We need to use some class libraries to generate QR codes. Now I will introduce how to use PHP QR Code to generate QR codes. The generation method is very simple. Let me introduce it below.

Use the php class library PHP QR Code to implement, no need to install additional php extensions
First download the class library package, sometimes the address cannot be opened
Address: http://phpqrcode.sourceforge.net/
Download: http://sourceforge.net/projects/phpqrcode/

Generally import the phpqrcode.php file when using it

Examples of specific usage

Direct browser output:

The code is as follows
 代码如下 复制代码

include "phpqrcode/phpqrcode.php";
$value="http://www.hzhuti.com";
$errorCorrectionLevel = "L";
$matrixPointSize = "4";
QRcode::png($value, false, $errorCorrectionLevel, $matrixPointSize);
exit;
?>

Copy code

 代码如下 复制代码


//文件输出
include('phpqrcode/phpqrcode.php');

// 二维码数据
$data = 'http://www.bKjia.c0m';

// 生成的文件名
$filename = '1111.png';

// 纠错级别:L、M、Q、H
$errorCorrectionLevel = 'L';

// 点的大小:1到10
$matrixPointSize = 4;
QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
?>

Include "phpqrcode/phpqrcode.php";

$value="http://www.hzhuti.com";
代码如下 复制代码


//生成中间带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"."
";
    $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');
?>

$errorCorrectionLevel = "L"; $matrixPointSize = "4"; QRcode::png($value, false, $errorCorrectionLevel, $matrixPointSize); exit; ?> Image file output
The code is as follows Copy code
 <🎜> //File output <🎜> Include('phpqrcode/phpqrcode.php'); <🎜>  <🎜> // QR code data <🎜> $data = 'http://www.bKjia.c0m'; <🎜>  <🎜> // Generated file name <🎜> $filename = '1111.png'; <🎜>  <🎜> // Correction levels: L, M, Q, H <🎜> $errorCorrectionLevel = 'L'; <🎜>  <🎜> // Point size: 1 to 10 <🎜> $matrixPointSize = 4; <🎜> QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2); <🎜> ?> Generate QR code with logo in the middle
The code is as follows Copy code
 <🎜> //Generate QR code with logo in the middle <🎜> 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"."
"; $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'); ?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633137.htmlTechArticleWe need to use some class libraries to generate QR codes. Below I will introduce the use of PHP QR Code generation QR code, the generation method is very simple, let me introduce it below. Using php classes...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn