This article will introduce to you how to generate and identify QR codes in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
Linear stacked QR codes
Matrix QR code
Large information capacity
Wide coding range
Strong fault tolerance
High decoding reliability
Encryption measures can be introduced
Low cost and easy to make
QR code technology has become a new channel for the spread of mobile phone viruses and phishing websites
Information leakage
PDF417: Chinese is not supported
DM: The patent is not disclosed and patent fees need to be paid
ps: Generate ordinary QR code
<?php include_once "./qrcode/phpqrcode.php"; /** * 参数:p1:二维码包含的内容 p2:输出的文件名 p3:容错级别 p4:大小 p5:外边距margin p6:保存路径 * 在浏览器上直接生成一个二维码(内容为abc) */ QRcode::png("abc"); QRcode::png("ABC",false,QR_ECLEVEL_L,10,5,false); /** * 生成文件到本地 * 参数:p1:二维码包含的内容 p2:输出的文件名 p3:容错级别 p4:大小 p5:外边距margin p6:是否保存并打印(false 直接生成 true 生成且打印) * PS:$saveandprint源码的p6参数做了修改 */ QRcode::png("ABC","ABC.jpg",QR_ECLEVEL_H,10,2,false);
ps: Generate QR code with Logo
<?php /** * Created by PhpStorm. * User: user * Date: 2018/8/16 * Time: 10:43 */ include "./qrcode/phpqrcode.php"; $txt = "测试内容"; $picPathAndName = "./pic/ABC.jpg";//二维码保存路径和名称 $level = 'L'; $size = 5; $is_logo = 1;//是否包含Logo 0否 1是 $margin = 2;//边距 $saveAndPrint = true;//是否保存,保存时,$picPathAndName设置为true //生成二维码图片QRcode::png($txt, $picPathAndName, $level, $size, $margin,$saveAndPrint); if($is_logo == 1){ $QR = $picPathAndName; //已经生成的原始二维码图 $Logo = './pic/logo.png'; $Logo_re = './pic/test_logo.png'; $QR = imagecreatefromstring(file_get_contents($QR)); $Logo = imagecreatefromstring(file_get_contents($Logo)); $QR_width = imagesx($QR); //二维码图片宽度 $QR_height = imagesy($QR); //二维码图片高度 $logo_width = imagesx($Logo); //logo图片宽度 $logo_height = imagesy($Logo); //logo图片高度 $logo_qr_width = $QR_width / 5; $scale = $logo_width / $logo_qr_width; $logo_qr_height = $logo_height / $scale; $from_width = ($QR_width - $logo_qr_width) / 2; imagecopyresampled($QR, $Logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height); //输出图片 imagepng($QR, $Logo_re); }
(Generate electronic signature)vCard format: https://zh.wikipedia.org/wiki/VCard
<?php /** * Created by PhpStorm. * User: user * Date: 2018/8/15 * Time: 23:00 */ require_once "./qrcode/phpqrcode.php"; /** * 生成电子签名 * PS;使用微信扫描二维码 */ $content = 'BEGIN:VCARD' . "\n";//起始标志 $content .= 'VERSION:2.1' . "\n";//当前版本 $content .= 'N:周' . "\n";//姓 $content .= 'FN:勇' . "\n";//名 $content .= 'ORG:江苏东大集成电路系统有限公司' . "\n";//公司名称 $content .= 'TITLE:PHP研发程序员' . "\n";//职位 $content .= 'TEL;WORK;VOICE:0523-83623173' . "\n";//工作电话 $content .= 'ADR;WORK:;;高新区星火路#2;南京市;江苏省;225762;中国' . "\n";//工作地址 $content .= 'ADR;HOME:;;下圩镇王横村178号;兴化市;江苏省;225762;中国' . "\n";//家庭地址(街道,地级市,省,邮编,国家) $content .= 'TEL;TYPE:18000001111' . "\n";//移动电话 $content .= 'EMAIL:123456@qq.com' . "\n";//邮箱 $content .= 'URL:www.baidu.com' . "\n";//个人主页 $content .= 'END:VCARD' . "\n";//结束标志 QRcode::png($content);
2. JQUERY generates QR CODE
##jquery_create.php
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Jquery生成二维码</title> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script type="text/javascript" src="./jquery-qrcode/jquery.qrcode.min.js"></script> </head> <body> <div id="qrcode"></div> <script> //$('#qrcode').qrcode("this plugin is great"); $('#qrcode').qrcode({width: 64,height: 64,text: "jason"}); </script> </body> </html>
Environment requirements, install the following extensions
- ImageMagick - zbar- php-zbarcode2. Method 2
PHP identifies QR code (no need to install extension) , ordinary QR codes can be tested initially, QR codes with logo, the fault tolerance level needs to be set higher, the page can be
qrReader class: https://github.com/baagee/php_QrReader<?php include_once('./qrReader/lib/QrReader.php'); $qrcode = new QrReader('./test_logo.png'); //图片路径 $text = $qrcode->text(); //返回识别后的文本 echo $text;
php video tutorial
The above is the detailed content of How to generate and identify QR codes with PHP. For more information, please follow other related articles on the PHP Chinese website!