search
Homephp教程php手册thinkphp整合系列之phpqrcode生成二维码

thinkphp整合系列之phpqrcode生成二维码
php生成二维码其实挺简单的;当然指的是使用qrcode类库;

因此关于是否要写这篇博客;我是犹豫了再三的;

不过最后还是决定写下吧;如果有童鞋急着用;就可以直接引了;

再个也可以作为即将写的文章微信支付生成的二维码做个铺垫;

老规矩;以bjyadmin项目示例:http://git.oschina.net/shuaibai123/thinkphp-bjyadmin

1:首先将/ThinkPHP/Library/Vendor/下的Phpqrcode文件夹拷贝到自己的项目中;

2:/Application/Common/Common/function.php增加如下函数/**<br>  * 生成二维码<br>  * @param  string  $url  url连接<br>  * @param  integer $size 尺寸 纯数字<br>  */<br> function qrcode($url,$size=4){<br>     Vendor('Phpqrcode.phpqrcode');<br>     // 如果没有http 则添加<br>     if (strpos($url, 'http')===false) {<br>         $url='http://'.$url;<br>     }<br>     QRcode::png($url,false,QR_ECLEVEL_L,$size,2,false,0xFFFFFF,0x000000);<br> }然后直接调用qrcode($url,$size)函数;第一个参数传链接;第二个参数传大小即可;

3:到这里已经可以生成二维码了;如果想对二维码更加个性化定制的话;

那么下面就来讲解下这堆参数的作用;png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4,<br>  $saveandprint=false, $back_color = 0xFFFFFF, $fore_color = 0x000000)第一个参数$text;就是上面代码里的URL网址参数;

第二个参数$outfile默认为否;不生成文件;只将二维码图片返回;否则需要给出存放生成二维码图片的路径;

第三个参数$level默认为L;这个参数可传递的值分别是L(QR_ECLEVEL_L,7%)、M(QR_ECLEVEL_M,15%)、Q(QR_ECLEVEL_Q,25%)、H(QR_ECLEVEL_H,30%);这个参数控制二维码容错率;不同的参数表示二维码可被覆盖的区域百分比。利用二维维码的容错率;我们可以将头像放置在生成的二维码图片任何区域;

第四个参数$size;控制生成图片的大小;默认为4;

第五个参数$margin;控制生成二维码的空白区域大小;

第六个参数$saveandprint;保存二维码图片并显示出来;$outfile必须传递图片路径;

第七个参数$back_color;背景颜色;

第八个参数$fore_color;绘制二维码的颜色;

note:第七、第八个参数需要传16进制是色值;并且要把“#”替换为“0x”
举个栗子:
白色:#FFFFFF => 0xFFFFFF
黑色:#000000 => 0x000000


更多用法;可以直接参考源代码了;http://phpqrcode.sourceforge.net/

thinkphp整合系列之phpqrcode生成二维码


本文为白俊遥原创文章,转载无需和我联系,但请注明来自白俊遥博客http://baijunyao.com

AD:真正免费,域名+虚机+企业邮箱=0元

Statement
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

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools