Download the phpQrCode extension library

The official download address: sourceforge.net/projects/ph…

Use the phpQrCode extension library

1. After decompression, open the following picture:

Phpqrcode. PHP: qrcode. PHP: qrcode. PHP: qrcode. PHP:

3. Place the phpQrCode folder in the Extend extension directory

 

4. Call in code

/ / reference
use phpqrcode\QRcode;
// Call library static methods
$qrcode=QRcode::png('QR code Content'.false.'Fault tolerance level'.'Picture size'.'Outer distance (white edge)');
Copy the code

5, sample


      
namespace app\index\controller;
use think\Controller;
use phpqrcode\QRcode;

class Qr extends Controller
{
	/** * generate two-dimensional code interface */
	public function api(){
		$data=input(' ');
		!isset($data['text'&&])$this->error('Invalid parameter');
		$text  = trim($data['text']); 
		// Calculate the size of the image
		$width = isset($data['width'])? trim($data['width') :100;	
		$size  = floor($width/37*100) /100 + 0.01;
		
		$errorCorrectionLevel =intval(2);// Fault tolerance level
      	$matrixPointSize = intval($size); // Generate the image size
		$margin =0;// Outer distance (white edge)
		$qrcode=QRcode::png($text.false.$errorCorrectionLevel.$matrixPointSize.$margin);
		die; }}? >
Copy the code