Home > Article > Backend Development > php generates QR code
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 = 'http://flyer0126.iteye.com'; function generateQRfromGoogle($data, $size=150, $level='L', $margin=0) { $data = urlencode($data); return 'http://chart.apis.google.com/chart?cht=qr&chs='.$size.'x'.$size.'&choe=UTF-8&chld='.$level.'|'.$margin.'&chl='.$data; } $src = generateQRfromGoogle($url, 100); echo "<img src='$src' alt='QR code'/>"; /** * 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('http://flyer0126.iteye.com', false, 'L', 4, 0);