PHP生成二维码

/**
 * QR Code 生成二维码
 * http://phpqrcode.sourceforge.net/
 */

/**
 * L级:约可纠错7%的数据码字
 * M级:约可纠错15%的数据码字
 * Q级:约可纠错25%的数据码字
 * H级:约可纠错30%的数据码字
 */

// 下载  http://phpqrcode.sourceforge.net/
include "phpqrcode/qrlib.php";

// 默认生成二维码
QRcode::png('abc');
// 第一个参数: 生成二维码的消息
// 第二个参数: 生成二维码的图片
// 第三个参数: QR_ECLEVEL--L级
// 第四个参数: 10--二维码大小
// 第五个参数: 0--外边距
// 第六个参数: true,,有bug,看源码,这个值无效,在浏览器打印并生成二维码
QRcode::png('abc', 'abc.jpg', QR_ECLEVEL, 10, 0, true);


public
static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveAndPrint = false)
{
    $enc = QRcode::factory($level, $size, $margin);
    return $enc->encodePNG($text, $outfile, $saveAndPrint);
}

public
static function text($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4)
{
    $enc = QRcode::factorv($level . $size . $margin);
}

/**
 * jquery.qrcode.js
 */

// <script src="http://cdn.bootcss.com/jquery/3.1.0/jquery.min.js"></script>
// <script src="jquery-qrcode-master/jquery.qrcode.min.js"></script>
// <script>
//  $('#qrcode').qrcode("this plugin is great");
//  $('#qrcode').qrcode({
//        width:64,
//        height:64,
//        text:"size does not matter",
//   });
// </script>


/**
 * 生成二维码电子名片
 */

include "./phpqrcode/qrlib.php";
$content = 'BEGIN:VCARD' . "\n";
$content .= 'VERSION:2.1' . "\n";
$content .= 'N:张' . "\n";
$content .= 'FN:三' . "\n";
$content .= 'END:VCARD' . "\n";

RQcode::png($content);

/**
 * 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 .= 'ORG:我是PHP的二维码' . "\n";
$content .= 'TEL;WORK;VOICE:18888888888' . "\n";
$content .= 'TEL;HOME;VOICE:18888888888' . "\n";
$content .= 'TEL;TYPE=cell:18888888888' . "\n";
$content .= 'ADR;HOME:;;详细地址' . "\n";
// 家庭住址
$content .= 'EMAIL:123@qq.com' . "\n";
$content .= 'URL:http://www.xxx.com' . "\n";
$content .= 'END:VCARD' . "\n";

RQcode::png($content);
RQcode::png($content, '明信片.jpg', QR_ECLEVEL_L, 3, 2);

/**
 * PHP识别二维码
 * 1,imageMagick
 * 2,zbar
 * 3,php-zbarcode
 *
 * php.ini
 * extension=pcntl.so
 * extension=zbarcode.so
 */

/**
 * qrcode_identify.php
 */
$image = new ZBarCodeImage("test.jpg");

$scanner = new ZBarCodeScanner();

$barcode = $scanner->scan($image);

if (!empty($barcode)) {
    //var_dump($barcode);
    foreach ($barcode as $code) {
        printf("Found type %s barcode with data %s\n", $code['type'], $code['data']);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值