Table of Contents
Classification of QR codes
Advantages and disadvantages of QR code
Advantages
Disadvantages
Three major international standards currently popular
QR CODE error correction ability
Prerequisite
1. PHP generates QR CODE
Directory structure
Home Backend Development PHP Tutorial How does PHP realize the generation and identification of QR codes (code)

How does PHP realize the generation and identification of QR codes (code)

Aug 18, 2018 pm 05:44 PM
php QR code

The content of this article is about how PHP realizes the generation and identification of QR codes (codes). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Recommended manual:php complete self-study manual

Classification of QR codes

  • linear stacked QR code

  • Matrix QR code

Advantages and disadvantages of QR code

Advantages

  • Large information capacity

  • Wide encoding range

  • Strong fault tolerance

  • High decoding reliability

  • Encryption measures can be introduced

  • Low cost and easy to produce

Disadvantages

  • QR code technology has become a new channel for the spread of mobile viruses and phishing websites

  • Information leakage

  • PDF417: Does not support Chinese

  • DM: Unpublished patent , need to pay patent fees

  • QR CODE: patent disclosure, support Chinese

QR CODE error correction ability

  • L level: approximately 7% of the data codewords can be corrected

  • M level: approximately 15% of the data codewords can be error corrected

  • Q level: approximately 25% of the data codewords can be corrected

  • H level: approximately 30% of the data codewords can be error corrected

Prerequisite

  • GD library

1. PHP generates QR CODE

  • Official website: http://phpqrcode.sourceforge.net/

  • Download source code: https://github.com/endroid/qr-code

Directory structure

How does PHP realize the generation and identification of QR codes (code)

##1. qrcode_create.php 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);
Copy after login

2. qrcode_logo.php 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 = &#39;L&#39;;$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 = &#39;./pic/logo.png&#39;;    
    $Logo_re = &#39;./pic/test_logo.png&#39;;    
    $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);
}
Copy after login

3. qrcode_vcard.php (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 = &#39;BEGIN:VCARD&#39; . "\n";//起始标志
     $content .= &#39;VERSION:2.1&#39; . "\n";//当前版本
     $content .= &#39;N:周&#39; . "\n";//姓$content .= &#39;FN:勇&#39; . "\n";//名
     $content .= &#39;ORG:江苏东大集成电路系统有限公司&#39; . "\n";//公司名称
     $content .= &#39;TITLE:PHP研发程序员&#39; . "\n";//职位
     $content .= &#39;TEL;WORK;VOICE:0523-83623173&#39; . "\n";//工作电话
     $content .= &#39;ADR;WORK:;;高新区星火路#2;南京市;江苏省;225762;中国&#39; . "\n";//工作地址
     $content .= &#39;ADR;HOME:;;下圩镇王横村178号;兴化市;江苏省;225762;中国&#39; . "\n";//家庭地址(街道,地级市,省,邮编,国家)
     $content .= &#39;TEL;TYPE:18000001111&#39; . "\n";//移动电话
     $content .= &#39;EMAIL:123456@qq.com&#39; . "\n";//邮箱
     $content .= &#39;URL:www.baidu.com&#39; . "\n";//个人主页
     $content .= &#39;END:VCARD&#39; . "\n";//结束标志
     QRcode::png($content);
    Copy after login
Recommended related articles: 1.
Example of PHP generating WeChat QR code2.
PHP URL conversion to generate QR code
Related video recommendations: 1.
Dugu Jiujian (4)_PHP video tutorial
2. JQUERY generates QR CODE

  • Source code address: https://github.com/jeromeetienne/jquery-qrcode

##jquery_create.php

<!DOCTYPE html><html lang="en"><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>
    <p id="qrcode"></p><script>
    //$(&#39;#qrcode&#39;).qrcode("this plugin is great");
    $(&#39;#qrcode&#39;).qrcode({width: 64,height: 64,text: "jason"});</script></body></html>
Copy after login
3. PHP identification QR code

1. Method 1

Environmental requirements, install the following extensions- ImageMagick
- zbar
- php-zbarcode

2. Method 2

PHP recognizes QR codes (no need to install extensions). For preliminary testing, ordinary QR codes are OK. For QR codes with logo, the fault tolerance level needs to be set higher. qrReader class: https://github.com/baagee/php_QrReader

<?phpinclude_once(&#39;./qrReader/lib/QrReader.php&#39;);
$qrcode = new QrReader(&#39;./test_logo.png&#39;);  //图片路径
$text = $qrcode->text(); //返回识别后的文本
echo $text;
Copy after login

Link: https://pan.baidu.com/s/1icpWRjIQiXdCXeOc52pNSg Password: c5y7

Related recommendations:

php uses open and fwrite to export files (code) in multiple formats

php implementation code for exporting Excel files in csv format

The above is the detailed content of How does PHP realize the generation and identification of QR codes (code). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles