PHP generated QR code is actually very simple, of course, refers to the use of QRCode class library;
So about whether to write this blog, I hesitated repeatedly;
But finally decided to write down, if there are children's shoes urgently use, it can be directly cited;
Another can also be written as the article to pay the generated two-dimensional code to do a cushion;
The usual; example of a bjyadmin project: Http://git.oschina.net/shuaibai123/thinkphp-bjyadmin
1: First copy the Phpqrcode folder under/thinkphp/library/vendor/to its own project;
2:/application/common/common/function.php Add the following function
/** * Generate QR Code * @param string $url URL connection * @param integer $size size Pure digital */function qrcode ($url, $size =4) {Vendor (' PHPQR Code.phpqrcode '); If there is no HTTP, add if (Strpos ($url, ' http ') ===false) {$url = ' http://'. $url; } QRCode::p ng ($url, false,qr_eclevel_l, $size, 2,false,0xffffff,0x000000);}
Then directly call the QRCode ($url, $size) function, the first parameter to link, the second parameter to the size of A;
3: It is possible to generate two-dimensional code here, if you want to personalize the QR code more customized;
Then the following is to explain the role of the stack of parameters;
PNG ($text, $outfile = False, $level = qr_eclevel_l, $size = 3, $margin = 4, $saveandprint =false, $back _color = 0xFFFFFF, $ Fore_color = 0x000000)
The first parameter is $text; the URL parameter in the above code;
The second parameter $outfile default is no, no file is generated, only the QR code image is returned;
The third parameter, $level, defaults to L; This parameter can pass values of L (qr_eclevel_l,7%), M (qr_eclevel_m,15%), Q (qr_eclevel_q,25%), H (qr_eclevel_h,30%), respectively. ; This parameter controls the fault tolerance of the two-dimensional code; Different parameters represent the percentage of the area where the QR code can be overwritten. The fault-tolerance ratio of two-dimensional code is used; we can place the avatar in any area of the generated QR code image;
The fourth parameter $size; controls the size of the generated picture; default is 4;
The fifth parameter $margin; control the size of the blank area of the generated QR code;
The sixth parameter $saveandprint; Save the image of the QR code and display it; $outfile must pass the picture path;
Seventh parameter $back_color; background color;
The eighth parameter $fore_color; draw the color of the two-dimensional code;
Note: The seventh and eighth parameters need to be 16 binary is the color value, and to replace "#" with "0x"
Give me a chestnut:
White: #FFFFFF = 0xFFFFFF
Black: #000000 = 0x000000
More usage; You can refer to the source code directly; http://phpqrcode.sourceforge.net/
650) this.width=650; "title=" Bai Jun Haruka Blog "src=" Http://baijunyao.com/Upload/image/ueditor/20160610/1465489804798656.jpg " alt= "Bai Jun Remote Blog" style= "border:0px;"/>
This article for Bai Jun Remote original article, reprinted without contact with me, but please specify from Bai Jun remote blog http://baijunyao.com
Thinkphp Integration Series of Phpqrcode to generate two-dimensional code