phpqrcode生成二维码直接输出(不用exit)
2021/4/28 20:28:31
本文主要是介绍phpqrcode生成二维码直接输出(不用exit),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
首先去官网下载PHPqrCode库文件,只需要里面的phpqrcode.php文件,下载地址:http://phpqrcode.sourceforge.net
/** * phpqrcode php生成二维码 * $frame string 二维码内容 * $filename string|false 默认为否,不生成文件,只将二维码图片返回,否则需要给出存放生成二维码图片的路径 * $level 默认为L,这个参数可传递的值分别是L(QR_ECLEVEL_L,7%),M(QR_ECLEVEL_M,15%),Q(QR_ECLEVEL_Q,25%),H(QR_ECLEVEL_H,30%)。这个参数控制二维码容错率,不同的参数表示二维码可被覆盖的区域百分比。 * $size int 生成二维码的区域大小点的大小:1到10 * $margin int 图片留白大小 * $saveandprint string 保存二维码图片并显示出来,$outfile必须传递图片路径 */ function qrcode($frame, $filename = false, $level = 'L', $size = 5, $margin = 2, $saveandprint=false){ header('Content-Type: image/png'); Vendor('phpqrcode.phpqrcode'); $qrcode = new \QRcode(); ob_clean(); $png = $qrcode->png($frame, $filename , $level , $size , $margin , $saveandprint); return $png; } /** * 生成二维码以base64输出, * $frame 二维码内容 * 参数同qrcode……………… */ function qrcode64($frame, $level = 'L', $size = 5, $margin = 2){ Vendor('phpqrcode.phpqrcode'); $QRcode = new \QRcode(); ob_start(); // 在服务器打开一个缓冲区来保存所有的输出 $QRcode->png($frame,false,$level,$size,$margin); $imageString = base64_encode(ob_get_contents()); ob_end_clean(); //清除缓冲区的内容,并将缓冲区关闭,但不会输出内容 return "data:image/jpg;base64,".$imageString; }
解释
qrcode();常规生成二维码 qrcode64以base64输出图片流使用时 $img = qrcode64('hello');echo "<img src='{$img}'>";
这篇关于phpqrcode生成二维码直接输出(不用exit)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-28怎么把PHP程序打包?-icode9专业技术文章分享
- 2024-09-28怎么用Phar打包PHP程序?-icode9专业技术文章分享
- 2024-09-13手动在github上下载的mfpt包,怎么放到thinkphp5.0框架并正常使用-icode9专业技术文章分享
- 2024-09-05python的<class 'bytearray'>相当于php的哪个数据类型-icode9专业技术文章分享
- 2024-09-05php 导出银行卡号避免科学技术法的方法-icode9专业技术文章分享
- 2024-08-30什么样的php代码质量差被称为垃圾代码-icode9专业技术文章分享
- 2024-08-30用 PHP 调用拼多多的接口以获取订单状态消息的步骤方法和代码示例-icode9专业技术文章分享
- 2024-08-27phpunit单元测试框架的入门和使用方法介绍-icode9专业技术文章分享
- 2024-08-24PHP 中date("w") 周一是多少-icode9专业技术文章分享
- 2024-08-14thinkphp8.0获取域名或主机名方法-icode9专业技术文章分享