Home > Backend Development > PHP Tutorial > php generates QR code

php generates QR code

巴扎黑
Release: 2016-11-22 16:00:49
Original
1141 people have browsed it

Two-dimensional barcode/QR code (2D code.QR Code-abbreviated from Quick Response Code, a form of 2D code-is the most known one) is to use a specific geometric figure according to certain rules on a plane (two-dimensional direction) (Above) The distributed black and white graphics record data symbol information. QR code is a common two-dimensional code.

There are two main ways to generate PHP:

<?php
/**
 * 二维码生成
 * 
 * @since 2013/02/27
 */
/**
 * 1.google open api
 * https://chart.googleapis.com/chart?cht=qr&chs=150×150&choe=UTF-8&chld=L|4&chl=http://flyer0126.iteye.com
 * 参数1 cht 指定一个QR码
 * 参数2 chs 图像大小,这是说生成图片尺寸为200×200,是宽x高。这并不是生成图片的真实尺寸,应该是最大尺寸。
 * 参数3 chl 指定的数据,也就是解码后看到的信息。包含中文时请使用UTF-8编码汉字,否则将出现问题。
 * 有两个可选参数
choe 编码 默认UTF8
chld 错误校正 默认7% L代表默认纠错水平; 4代表margin,即二维码边界空白大小,可自行调节。
 * 
 * @var unknown_type
 */
$url = &#39;http://flyer0126.iteye.com&#39;;
function generateQRfromGoogle($data, $size=150, $level=&#39;L&#39;, $margin=0)
{
$data = urlencode($data);
return &#39;http://chart.apis.google.com/chart?cht=qr&chs=&#39;.$size.&#39;x&#39;.$size.&#39;&choe=UTF-8&chld=&#39;.$level.&#39;|&#39;.$margin.&#39;&chl=&#39;.$data;
}
$src = generateQRfromGoogle($url, 100);
echo "<img src=&#39;$src&#39; alt=&#39;QR code&#39;/>";
/**
 * 2.类库PHP QR Code
 * 主页地址:http://phpqrcode.sourceforge.net/
 * 下载:http://sourceforge.net/projects/phpqrcode/
 * 
 * $data 数据
 * $filename 保存的图片名称
 * $errorCorrectionLevel 错误处理级别
 * $matrixPointSize 每个黑点的像素
 * $margin 图片外围的白色边框像素
 */
include "qrlib.php";
//QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, $margin);
QRcode::png(&#39;http://flyer0126.iteye.com&#39;, false, &#39;L&#39;, 4, 0);
Copy after login


Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template