当前位置:网站首页>TP5 generates the most detailed two-dimensional code tp6 (also available)
TP5 generates the most detailed two-dimensional code tp6 (also available)
2022-06-27 18:23:00 【When you're lonely, the dog stays with you】
effect :

One : download phpqrcode Class file
1. Download address :PHP QR Code download | SourceForge.net
After downloading, unzip it and put it in tp5 In the framework vendor Below directory (vendor Generally store third-party plug-ins )


2.PHP The environment must turn on support GD2 Extended library support ( It's usually on )
3. The preparations are all done , The next step is the code part , Just write and call the following methods in the controller , You can see the QR code you want
Be careful : The following code is tp5 Generate qr code ,tp6 Words Use require introduce phpqrcode.php, Just open tp6 notes , notes tp5 vendor Methods introduced
/// QR code public function createImg($url='') { vendor('phpqrcode.phpqrcode');// Introducing class library tp5 // require "../vendor/phpqccode/phpqrcode.php";//tp6 Introducing class library methods $value = $url; // QR code content $errorCorrectionLevel = 'L'; // Fault tolerance level $matrixPointSize = 5; // Generate image size // Generate QR code image // Determine whether this folder exists If not, create one if (!is_dir("qrcode")) { // Create file plus mkdir("qrcode"); } // Set the QR code file name $filename = './qrcode/' . time() . rand(10000, 9999999) . '.png'; // Generate qr code \QRcode::png($value, $filename, $errorCorrectionLevel, $matrixPointSize, 2); return $filename; }
4. call
Use the call where you need it , The two-dimensional code will be generated and returned to us with a path , The picture is already in public/qrcode/ To generate, you only need to splice our domain name to access
$img = $this-> createImg($orderNumber);// QR code path 5.
This is the third step if you need to convert base64 Data paste the following code can be slightly modified
// If you need to convert to base64 data , Just untangle the line below
//$image_data = chunk_split(base64_encode(fread(fopen($filename, 'r'), filesize($filename))));
// Get the current domain name $request = Request::instance(); $domain = $request->domain();
return $domain.'/'.$filename;
} belt logo Two dimensional code
function scerweima1($url=''){
Vendor('phpqrcode.phpqrcode');
$value = $url; // QR code content
$errorCorrectionLevel = 'H'; // Fault tolerance level
$matrixPointSize = 6; // Generate image size
// Generate QR code image
$filename = './qrcode/' . time() . rand(10000, 9999999) . '.png';
QRcode::png($value,$filename , $errorCorrectionLevel, $matrixPointSize, 2);
$logo = VENDOR_PATH.'phpqrcode\images'.'\logo.png'; // Ready logo picture
$QR = $filename; // The original QR code graph that has been generated
if (file_exists($logo)) {
$QR = imagecreatefromstring(file_get_contents($QR)); // Target image connection resource .
$logo = imagecreatefromstring(file_get_contents($logo)); // Source image connection resource .
$QR_width = imagesx($QR); // QR code image width
$QR_height = imagesy($QR); // QR code image height
$logo_width = imagesx($logo); //logo Image width
$logo_height = imagesy($logo); //logo Picture height
$logo_qr_width = $QR_width / 4; // After the combination logo Width ( Take up... Of QR code 1/5)
$scale = $logo_width/$logo_qr_width; //logo Width scaling ratio ( The width of itself / Combined width )
$logo_qr_height = $logo_height/$scale; // After the combination logo Height
$from_width = ($QR_width - $logo_qr_width) / 2; // After the combination logo The coordinate point of the upper left corner
// Recombine the picture and resize
/*
* imagecopyresampled() Put an image ( Source image ) Copy a square area in to another image
*/
imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,$logo_qr_height, $logo_width, $logo_height);
}
// Output pictures
imagepng($QR, 'qrcode.png');
imagedestroy($QR);
imagedestroy($logo);
return '<img src="qrcode.png" alt=" Use wechat to scan payment ">';
}
The same way .边栏推荐
- Oracle concept II
- Unity 阴影——阴影平坠(Shadow pancaking)
- 【多线程】线程通信调度、等待集 wait() 、notify()
- [the way of programmer training] - 3 Character count statistics
- Missing d3d10 How to repair DLL files? Where can I download d3d10.dll
- Popularization of MCU IO port: detailed explanation of push-pull output and open drain output
- Offline disk group
- d3dx9_ How to repair 25.dll? d3dx9_ 25.dll where to download
- DOM object in JS
- 软件测试学习-黑马程序员,软件测试学习大纲
猜你喜欢

如何提升IT电子设备效能管理

DOM object in JS

d3dx9_ How to repair 40.dll? Win10 system d3dx9_ What if 40.dll is lost?

Computing trends in three times of machine learning

Anfulai embedded weekly report (issue 252): February 7, 2022 to February 13, 2022

建立自己的网站(10)

Wanzhou gold industry: what knowledge points do you need to master to invest in precious metals?

Explain the distributed computing of Apache skywalking OAP in detail

Lvgl8.x migrating to stm32f4

Control file related views
随机推荐
leetcode 69. Square root of X
Dark horse programmer - software testing foundation class -02-30-45 tools open browser running code, audio, video, test points, audio and video labels, layout labels. Advanced hyperlink syntax, absolu
Defiato is an innovation that combines user-friendly features of a centralized platform with defi services
【多线程】线程通信调度、等待集 wait() 、notify()
Leetcode 46 Full Permutation
Study on heritability and field experiment design
Oracle concept II
Offline disk group
如何制作登录界面
What do fast fashion brands care more about?
How can Seata performance be improved? For example, add a computing node to the database?
Oracle concept II
09 route guard authenticates URL
leetcode 70. climb stairs
d3dx9_ 39.dll how to repair -d3dx9_ 39.dll missing file download
How to improve it electronic equipment performance management
Delete duplicate elements in the sorting linked list
Sword finger offer 22 The penultimate node in the linked list
Overview of Inspur Yunxi database executor
10 minutes to master the installation steps of MySQL