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
    吃惊
    嘿嘿。能够自己试一试 玩玩。德玛上单。不给就送哦。



  • 相关阅读:
    init_machine 在Kernel中被调用的过程
    maven-surefire-plugin的forkMode分析
    执行Maven install或Maven test命令时控制台输出乱码的解决办法
    Maven 中的dependencies与dependencyManagement的区别
    使用maven profile实现多环境可移植构建
    Maven最佳实践:划分模块
    MySQL的登陆错误:ERROR 1049 (42000): Unknown database 'root'
    Java 连接操作 Redis 出现错误
    关闭多个screen
    linux sed 批量替换字符串
  • 原文地址:https://www.cnblogs.com/slgkaifa/p/7073402.html
Copyright © 2011-2022 走看看