当前位置:网站首页>PHP QRCode生成二维码
PHP QRCode生成二维码
2022-07-16 04:43:00 【梦里逆天】
1.二维码概述
二维条码/二维码(2-dimensional bar
code)是用某种特定的几何图形按一定规律在平面(二维方向上)分布的黑白相间的图形记录数据符号信息的;在代码编制上巧妙地利用构成计算机内部逻辑基础的“0”、“1”比特流的概念。一维条码/条形码:是由一组粗细不同、黑白(或彩色)相间的条、空及其相应的字符(数字字母)组成的标记,即传统条码。
二维条码是用某种特定的几何图形按一定规律在平面(二位方向)上分布的条、空相间的图形来记录数据符号信息。
2.二维码的分类
根据编码原理:
- 先行堆叠式二维码:堆叠式/行排式二维条码其编码原理是建立在一维条码基础上,按需要堆积成二行或多行。
- 矩阵式二维码:矩阵式二维条码(又称棋盘式二维条码)是在一个矩形空间通过黑、白像素在矩阵中的不同分布进行编码。在矩阵相应元素位置上,用点(方点、圆点或其他形状)的出现表示二进制“1”,点的不出现表示为二进制的“0”
3.二维码的优缺点
优点:
- 信息容量大;
- 编码范围广;
- 容错能力强;(部分缺失不影响功能)
- 驿马可靠性高;
- 可引入加密措施;
- 成本低,易制作 缺点:
- 二维码技术成为手机病毒、钓鱼网站传播的新渠道;
- 信息泄密;
4.OR Code介绍
目前留下的三大国际标准:
- PDF417:不支持中文;
- DM:专利未公开,需支付专利费用;
- QR Code:专利公开,支持中文 与其他二维码相比,具有识读速度快、数据密度大、占用空间小等优势。 Quick Response Code。
纠错能力(二维码被破坏时,依然可以保持数据的完整性):
- L级:约可纠错7%的数据码字;
- M级:约可纠错15%的数据码字;
- Q级:约可纠错25%的数据码字;
- H级:约可纠错30%的数据码字
5 php 生成QR Code
下载phpqrcode源码:https://sourceforge.net/projects/phpqrcode/files/latest/download
解压后复制到项目文件夹
编写代码
<?php
include_once 'phpqrcode/qrlib.php';
/** * png函数的参数: * $text:保存的文本内容; * $outfile:是否输出为文件,默认false * $level:纠错能力级别 * $size:大小 * $margin:边距 * $saveandprint:是否保存并打印,默认false */
//QRCode::png('abc');
QRCode::png('abc1', 'abc1.jpg'); // 浏览器不输出,保存为图片
//QRCode::png('abc', false, QR_ECLEVEL_L, 10, 0);
QRCode::png('abc2', 'abc_2.jpg', QR_ECLEVEL_L, 10, 0, true);
abc1.jpg
abc_2.jpg
Alt+鼠标左键,点击"png”进入png函数的源码,就会发现这里有bug,设置了saveandprint的值固定是false,而没有接收传进来的值,导致无法打印并保存。这里只需要把“=false”去掉即可。

6. jquery生成QR Code
下载jquery-qrcode:https://gitee.com/mlnt/jquery-qrcode
解压后复制到项目文件夹
编写html代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>qrcode</title>
</head>
<body>
<div id="qrcode"></div>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="jquery-qrcode-master/jquery.qrcode.min.js"></script>
<script type="text/javascript"> $('#qrcode').qrcode("Hello world"); $('#qrcode').qrcode({
width: 64, height: 64, text: "This is a test."}); </script>
</body>
</html>

7. php生成电子名片
<?php
// php 生成电子名片
include_once './phpqrcode/qrlib.php';
/** * N:姓 * FN:名 * ORG:公司地址 * TEL;WORK;VOICE:工作单位电话 * TEL;HOME;VOICE:家里电话 * TEL;TYPE=cell:移动电话 * ADR;HOME:家庭地址 * EMAIL:邮箱 * URL:网址 * */
$content = 'BEGIN:VCARD'."\n";
$content .= 'VERSION:2.1'."\n";
$content .= 'N:张'."\n";
$content .= 'FN:三'."\n";
$content .= 'END:VCARD'."\n";
QRcode::png($content);

扫码结果:
<?php
// php 生成电子名片
include_once './phpqrcode/qrlib.php';
/** * N:姓 * FN:名 * ORG:公司地址 * TEL;WORK;VOICE:工作单位电话 * TEL;HOME;VOICE:家里电话 * TEL;TYPE=cell:移动电话 * ADR;HOME:家庭地址 * EMAIL:邮箱 * URL:网址 * */
$content = 'BEGIN:VCARD'."\n";
$content .= 'VERSION:2.1'."\n";
$content .= 'N:张'."\n"; // 姓
$content .= 'FN:三'."\n"; // 名
$content .= 'NICKNAME:法外狂徒'."\n"; // 别名
$content .= 'BDAY:1997-07-01'."\n"; // 生日
$content .= "NOTE:人一定要有梦想,有了梦想,你才能是一个真正有梦想的人。"."\n"; // 备注
$content .= 'ORG:中国刑法之光研究所'."\n"; // 公司地址
$content .= 'TITLE:项目经理'."\n"; // 头衔
$content .= 'TEL;WORK;VOICE:123321666'."\n"; // 工作单位电话
$content .= 'TEL;HOME;VOICE:134502404'."\n"; // 家里电话
$content .= 'TEL;TYPE=cell:143666888'."\n"; // 移动电话
$content .= 'ADR;HOME:;;法外大道404号;北城区;哥谭市;438384;中国'."\n"; // 家庭住址
$content .= 'EMAIL:[email protected]'."\n"; // 邮箱
$content .= 'END:VCARD'."\n";
QRcode::png($content);
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4bZ3vMzg-1657894210344)(assets/20220715220408.jpg)]](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
扫描结果:![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-KP03TIwu-1657894210344)(assets/20220715220522.jpg)]](/img/be/81ade4288a35433a38bd209a19d5d6.jpg)
参考文章:
边栏推荐
- PMP practice once a day | don't get lost in the exam -7.14
- 【目标跟踪】基于背景消减的图像帧间差分法目标检测及matlab仿真
- 騰訊員工發帖找對象,錶示偏愛程序員!評論火了......丨黑馬頭條
- T100开发全新双档程序详细步骤
- base64编码解码原理和C语言实现
- ubuntu 18.04 使用 tar包安装mysql5.7.35
- The principle and implementation of PageRank
- marginalization
- Optimization design of video processing and codec hardware system
- 解道--探索术
猜你喜欢

Sword finger offer19 regular expression matching string dynamic programming

Ora-19625 exception handling record

base64编码解码原理和C语言实现

The open and closed interval of the mean value theorem of higher numbers | integrals, the first mean value theorem of integrals and its generalization

Cultural tourism night tour project helps the development of night economy

T100 user defined application instructions (azzi650)

二叉树,遍历

MySQL window function running average

Golang---------小试牛刀 gin框架文件上传

Linux中安装mysql 5.7.23
随机推荐
Two low-cost ways to attract users with integral check-in
Single cell literature learning (Part4) -- scanpy: large scale single cell gene expression data analysis
Ora-19625 exception handling record
Feign implements inter service and passes headers when calling
Keep an IT training diary 068- a little unbalanced in my heart
XML file delete comments
2.4_ 9 MySQL by separator, row to column
PMP每日一练 | 考试不迷路-7.14
Can ping command still play like this?
騰訊員工發帖找對象,錶示偏愛程序員!評論火了......丨黑馬頭條
Video processing: video sampling
T100debug操作记录
ORA-600:[qertbGetPartitionNumber:qesma2],[],[],[]
剑指Offer19-正则表达式匹配-字符串-动态规划
清楚临时表、查看临时表占用内存
Golang---------小试牛刀 gin框架文件上传
Matlab机械臂建模运动学仿真+轨迹规划
iptables屏蔽ip某个端口访问
The version of NPM does not match that of node. When the NPM result is updated, an error is reported. How can the previous NPM version be returned? Or how to check the NPM version of node adaptation
Opencv:05 filter