当前位置:网站首页>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 .边栏推荐
- About redis master-slave replication
- [leetcode] 2. Add two numbers (user-defined listnode), medium
- Oracle concept II
- Generate zip package command
- How can Seata performance be improved? For example, add a computing node to the database?
- Introduction to photoswape
- 06. First introduction to express
- Byte + Google super full kotlin learning King fried notes! Kotlin introductory tutorial + Advanced kotlin enhanced actual combat (with demo)
- Related configuration commands of Huawei LACP
- [JS reverse hundreds of examples] I love to solve 2022 Spring Festival problems and receive red envelopes
猜你喜欢

全面解析零知识证明:消解扩容难题 重新定义「隐私安全」

leetcode 69. Square root of X
![[the way of programmer training] - 3 Character count statistics](/img/0c/e506571a4b22edc7c02a346909eeab.jpg)
[the way of programmer training] - 3 Character count statistics

428 binary tree (501. mode in binary search tree, 701. insert operation in binary search tree, 450. delete node in binary search tree, 669. prune binary search tree)

Autodesk Navisworks 2022软件安装包下载及安装教程

Shardingsphere & Atlas & MYCAT comparison

Community sharing jumpserver in the eyes of senior open source users: a fortress machine for "Crazy" iteration

Synchronization mechanism of dual namenodes

Wanzhou gold industry: what are the common gold investment and warehouse building modes?

Offline disk group
随机推荐
[UVM basics] UVM tree organizational structure
When the publish / subscribe mode encounters NET
(5) SPI application design and simulation verification 3 - verification code implementation
建立自己的网站(10)
Teach you how to realize pynq-z2 bar code recognition
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
Handling method of occasional error reporting on overseas equipment
[leetcode] 2. Add two numbers (user-defined listnode), medium
leetcode 70. climb stairs
d3dx9_ How to repair 38.dll? d3dx9_ 38. How to download a missing DLL?
Written in eclipse, problems after querying the database connection
09 route guard authenticates URL
[Tang Laoshi] C -- encapsulation: member method
Lvgl8.x migrating to stm32f4
Oracle的NUMBER长度超过19之后,实体使用Long映射,导致出现问题是为什么?
About redis master-slave replication
seata-server 端数据库连接用户、业务数据库 undo_log 所属用户都需要什么权限?
软件测试学习-黑马程序员,软件测试学习大纲
[JS reverse hundreds of examples] I love to solve 2022 Spring Festival problems and receive red envelopes
广汽三菱全新欧蓝德首次国内亮相于年内上市 产品力全面焕新