Home Backend Development PHP Tutorial Encapsulation of QR code generation in TP5

Encapsulation of QR code generation in TP5

Dec 22, 2017 am 11:54 AM
tp5 QR code generate

Nowadays, QR codes are widely used, and some websites also have the need to generate QR codes. This article uses TP5 as an example to encapsulate the function of generating a QR code.

1. Download the QR code plug-in Phpqrcode at https://sourceforge.net/projects/phpqrcode/files/, and put the downloaded folder under \thinkphp\vendor


2. Add the function qrcode() in the controller (or in the public function library);


  /**
     * 制作二维码图片
     * @return [type] [description]
     */
    public function qrcode() {
    //加载第三方类库
        vendor('phpqrcode.phpqrcode');
        $url="http://finance.china.com.cn/hz/gn/2345/20171127/19523.shtml";
        $size=4;    //图片大小
        $errorCorrectionLevel = "Q"; // 容错级别:L、M、Q、H
        $matrixPointSize = "8"; // 点的大小:1到10
        //实例化
        $qr = new \QRcode();
        //会清除缓冲区的内容,并将缓冲区关闭,但不会输出内容。
        ob_end_clean();
    //输入二维码
        $qr::png($url, false, $errorCorrectionLevel, $matrixPointSize);
               
    }
Copy after login
参数说明:
/*
* png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 4, $margin = 4, $saveandprint=false, $back_color = 0xFFFFFF, $fore_color = 0x000000)
* 参数说明:
* $text 就是url参数
* $outfile 默认否,不生成文件,只返回二维码图片,否则需要给出保存路径
* $level 二维码容错率,默认L(7%)、M(15%)、Q(25%)、H(30%)
* $size 二维码图片大小,默认4
* $margin 二维码空白区域大小
* $saveabdprint 二维码保存并显示,$outfile必须传路径
* $back_color 背景颜色
* $fore_color 绘制二维码的颜色
* tip:颜色必须传16进制的色值,并把“#”替换为“0x”; 如 #FFFFFF => 0xFFFFFF
*/
Copy after login


3. QR code generation and calling. For example: website domain name /index/index/qrcode, you can display the QR code.

Related reading:

How to get openid after scanning the QR code image generated by PHP?

Yii2.0 framework generates QR code function implementation code

## Use Thinkphp3.2 combined with phpqrcode to generate 2D code code

The above is the detailed content of Encapsulation of QR code generation in TP5. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to create a QR code using wps How to create a QR code using wps Mar 28, 2024 am 09:41 AM

1. Open the software and enter the wps text operation interface. 2. Find the insert option in this interface. 3. Click the Insert option and find the QR code option in its editing tool area. 4. Click the QR code option to pop up the QR code dialog box. 5. Select the text option on the left and enter our information in the text box. 6. On the right side, you can set the shape of the QR code and the color of the QR code.

How to use PHP to dynamically generate QR codes How to use PHP to dynamically generate QR codes Sep 05, 2023 pm 05:45 PM

How to use PHP to dynamically generate QR codes. QR codes (QRCode) are widely used in various fields. They can store a large amount of information and are easy to scan. In web applications, we often need to dynamically generate QR codes to provide users with convenient operations. This article will introduce how to use PHP to dynamically generate QR codes. 1. Install and configure the PHPQRCode library. In order to facilitate the generation of QR codes, we can use the PHPQRCode library. First, we need

How to scan QR codes on iPhone How to scan QR codes on iPhone May 04, 2023 am 11:46 AM

Prerequisite: Enable QR code scanning on your iPhone The ability to scan QR codes is enabled by default on all iPhones running iOS 11. Therefore, you need to make sure your iPhone is updated to the latest available version, at least iOS11, to be able to scan QR codes natively. Before proceeding with any of the methods below, you must ensure that the feature is enabled on your iPhone. You can enable QR code scanning on your iPhone by opening the Settings app and tapping the Camera section. On the next screen, enable the "Scan QR code" toggle. This should turn on the feature so you can scan and extract from QR codes using any of the following methods

How to generate k random dates between two dates using Python? How to generate k random dates between two dates using Python? Sep 09, 2023 pm 08:17 PM

Generating random data is very important in the field of data science. From building neural network predictions, stock market data, etc., date is usually used as one of the parameters. We may need to generate random numbers between two dates for statistical analysis. This article will show how to generate k random dates between two given dates using the random and datetime modules. Datetime is Python’s built-in library for handling time. On the other hand, the random module helps in generating random numbers. So we can combine random and datetime modules to generate a random date between two dates. Syntax random.randint (start, end, k) random here refers to the Python random library. The randint method uses three important

How to generate refreshable image verification code using PHP How to generate refreshable image verification code using PHP Sep 13, 2023 am 11:54 AM

How to use PHP to generate refreshable image verification codes. With the development of the Internet, in order to prevent malicious attacks and automatic machine operations, many websites use verification codes for user verification. One common type of verification code is the image verification code, which generates a picture containing random characters and requires the user to enter the correct characters before proceeding. This article will introduce how to use PHP to generate refreshable image verification codes and provide specific code examples. Step 1: Create a verification code image First, we need to create a verification code image

How to use PHP to generate batch QR codes? How to use PHP to generate batch QR codes? Aug 25, 2023 pm 04:33 PM

How to use PHP to generate batch QR codes? With the continuous development of Internet technology, QR codes have become a very common information transmission tool. QR codes can store a large amount of information and can be quickly scanned and recognized, so they have been widely used in various industries. In many cases, we need to generate a large number of QR codes in batches, such as for product labels, event tickets, etc. PHP is a scripting language widely used in web development and is flexible, simple and easy to use. Below, we will introduce how to use PHP to generate

No longer worry about being stopped by your boss for a small meeting before get off work. The AI ​​assistant will help you automatically generate meeting minutes. No longer worry about being stopped by your boss for a small meeting before get off work. The AI ​​assistant will help you automatically generate meeting minutes. Sep 04, 2023 pm 11:21 PM

iFlytek has upgraded the meeting minutes function, which can directly convert spoken expressions into written drafts, and AI can summarize meeting minutes based on recordings. AI can help you complete the writing of meeting minutes. On August 31, the iFlytek web version was upgraded, adding a real-time recording function on the PC side, which can use artificial intelligence to intelligently generate meeting minutes. The launch of this function will greatly improve the efficiency of users in organizing content and following up on key work items after meetings. For people who often attend meetings, this function is undoubtedly a very practical tool that can save a lot of time and energy. The application scenario of this function is mainly to convert recordings on the PC to text and automatically generate meeting minutes, aiming to provide users with the best quality. Products with excellent services and the most advanced technology to quickly improve office efficiency

How to do basic natural language generation using PHP How to do basic natural language generation using PHP Jun 22, 2023 am 11:05 AM

Natural language generation is an artificial intelligence technology that converts data into natural language text. In today's big data era, more and more businesses need to visualize or present data to users, and natural language generation is a very effective method. PHP is a very popular server-side scripting language that can be used to develop web applications. This article will briefly introduce how to use PHP for basic natural language generation. Introducing the natural language generation library The function library that comes with PHP does not include the functions required for natural language generation, so

See all articles