zoukankan      html  css  js  c++  java
  • PHP生成二维码的2种方式

    微笑二维码的用处俺也就不说了,看一下用PHP生成的二维码吧。

    利用谷歌提供的API 生成二维码,如今非常多国外站点都提供了这类API

    看下代码吧《=======================》

    <?php
    $urlToEncode="http://gz.altmi.com"; 
    generateQRfromGoogle($urlToEncode); 
    function generateQRfromGoogle($chl,$widhtHeight ='150',$EC_level='L',$margin='0') 
    { 
        $url = urlencode($url);  
        echo '<img src="http://chart.apis.google.com/chart?

    chs='.$widhtHeight.'x'.$widhtHeight.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$chl.'" alt="QR code" widhtHeight="'.$size.'" widhtHeight="'.$size.'"/>'; } ?>

    上面的方式特别的简便,可是假设人家站点不提供这样的API 了,我们岂不是要歇菜了么?还是用我们的PHP 类库吧

    php类库PHP QR Code
    地址:http://phpqrcode.sourceforge.net/
    下载:http://sourceforge.net/projects/phpqrcode/

    实例:

    <?

    php include('./phpqrcode/phpqrcode.php'); // 二维码数据 $data = 'http://gz.altmi.com'; // 生成的文件名称 $filename = $errorCorrectionLevel.'|'.$matrixPointSize.'.png'; // 纠错级别:L、M、Q、H $errorCorrectionLevel = 'L'; // 点的大小:1到10 $matrixPointSize = 4; QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2); ?>

    官方给出的用例:
    <?php
    # include这两个文件之中的一个:
    /*
    qrlib.php for full version (also you have to provide all library files 
    form package plus cache dir)
    
    OR phpqrcode.php for merged version (only one file, 
    but slower and less accurate code because disabled cache
    and quicker masking configured)
    */
    # 两句话解释:
    # 包括qrlib.php的话须要同其他文件放到一起:文件、目录。
    # phpqrcode.php是合并后版本号。仅仅须要包括这个文件,但生成的图片速度慢并且不太准确
    # 下面给出两种使用方法:
    
    # 创建一个二维码文件
    QRcode::png('code data text', 'filename.png');
    // creates file
    
    # 生成图片到浏览器
    QRcode::png('some othertext 1234');
    // creates code image and outputs it directly into browser
    吃惊
    嘿嘿。能够自己试一试 玩玩。德玛上单。不给就送哦。



  • 相关阅读:
    python前端CSS
    python 前端HTML
    python-day08网络编程
    python学生选课系统
    python-day07-面向对象进阶
    列表补充,列表的组合、查询元素是否存在列表,查询元素出现在列表中几次
    list补充,append()、extend()、insert()、remove()、del()、pop()、分片
    python第五天,两个知识点三目运算符和assert抛异常处理。
    运算符补充
    python第四天,list补充
  • 原文地址:https://www.cnblogs.com/slgkaifa/p/7073402.html
Copyright © 2011-2022 走看看