search
HomePHP FrameworkThinkPHPA brief discussion on how ThinkPHP+phpqrcode generates QR codes

How to generate QR code in ThinkPHP? The following article will introduce to you how ThinkPHP uses the phpqrcode extension library to generate QR codes. I hope it will be helpful to you!

A brief discussion on how ThinkPHP+phpqrcode generates QR codes

1. Download the phpqrcode extension library

Official download address: https://sourceforge.net /projects/phpqrcode/files/

[Related tutorial recommendations: thinkphp framework]

2. Use the phpqrcode extension library

1. After decompression, open the following picture:

2. In order to facilitate the call, we can modify phpqrcode Change the file name .php to "QRcode.php", and then add the namespace, as follows:

3. Put the phpqrcode folder into extend extension directory

4. Call

//引用
use phpqrcode\QRcode;
//调用类库静态方法
$qrcode=QRcode::png('二维码内容',false, '容错级别', '图片大小', '外边距离(白边)	');

5 in the code. Example

<?php
namespace app\index\controller;
use think\Controller;
use phpqrcode\QRcode;

class Qr extends Controller
{
	/**
     * 生成二维码接口
     */
	public function api(){
		$data=input(&#39;&#39;);
		!isset($data[&#39;text&#39;]) && $this->error(&#39;参数非法&#39;);
		$text  = trim($data[&#39;text&#39;]); 
		//计算图片尺寸
		$width = isset($data[&#39;width&#39;]) ? trim($data[&#39;width&#39;]):100;	
		$size  = floor($width/37*100)/100 + 0.01;
		
		$errorCorrectionLevel =intval(2) ;//容错级别 
      	$matrixPointSize = intval($size); //生成图片大小 
		$margin =0;//外边距离(白边)		
		$qrcode=QRcode::png($text,false, $errorCorrectionLevel, $matrixPointSize, $margin);
		die;
	}
}
?>

Original address: https:/ /juejin.cn/post/6986282985829957669

Author: Yuan Ge

Recommended study: "PHP Video Tutorial"

The above is the detailed content of A brief discussion on how ThinkPHP+phpqrcode generates QR codes. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:掘金--元歌. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software