zoukankan      html  css  js  c++  java
  • tp5 生成二维码

    一:下载phpqrcode类文件

    1.下载地址:https://sourceforge.net/projects/phpqrcode/

    2.PHP环境必须开启支持GD2扩展库支持(一般情况下都是开启状态)

    二:在image文件中上传logo.png文件,上传是为了为最后的结果做准备

    三:在common中写我们要用的方法

    function scerweima($url=''){
    Vendor('phpqrcode.phpqrcode');
    $value = $url; //二维码内容
    $errorCorrectionLevel = 'L'; //容错级别
    $matrixPointSize = 5; //生成图片大小
    //生成二维码图片
    $filename = VENDOR_PATH.'phpqrcodeimages'.microtime().'.png';
    QRcode::png($value,$filename , $errorCorrectionLevel, $matrixPointSize, 2);
    $QR = $filename; //已经生成的原始二维码图片文件
    $QR = imagecreatefromstring(file_get_contents($QR));
    //输出图片
    imagepng($QR, 'qrcode.png');
    imagedestroy($QR);
    return '<img src="qrcode.png" alt="使用微信扫描支付">';
    }
    然后在需要引用的时候直接调用就行这个是不带logo的下面的是带logo的
    function scerweima1($url=''){
    Vendor('phpqrcode.phpqrcode');
    $value = $url; //二维码内容
    $errorCorrectionLevel = 'H'; //容错级别
    $matrixPointSize = 6; //生成图片大小
    //生成二维码图片
    $filename = VENDOR_PATH.'phpqrcodeimages'.microtime().'.png';
    QRcode::png($value,$filename , $errorCorrectionLevel, $matrixPointSize, 2);
    $logo = VENDOR_PATH.'phpqrcodeimages'.'logo.png'; //准备好的logo图片
    $QR = $filename; //已经生成的原始二维码图
    if (file_exists($logo)) {
    $QR = imagecreatefromstring(file_get_contents($QR)); //目标图象连接资源。
    $logo = imagecreatefromstring(file_get_contents($logo)); //源图象连接资源。
    $QR_width = imagesx($QR); //二维码图片宽度
    $QR_height = imagesy($QR); //二维码图片高度
    $logo_width = imagesx($logo); //logo图片宽度
    $logo_height = imagesy($logo); //logo图片高度
    $logo_qr_width = $QR_width / 4; //组合之后logo的宽度(占二维码的1/5)
    $scale = $logo_width/$logo_qr_width; //logo的宽度缩放比(本身宽度/组合后的宽度)
    $logo_qr_height = $logo_height/$scale; //组合之后logo的高度
    $from_width = ($QR_width - $logo_qr_width) / 2; //组合之后logo左上角所在坐标点
    //重新组合图片并调整大小
    /*
    * imagecopyresampled() 将一幅图像(源图象)中的一块正方形区域拷贝到另一个图像中
    */
    imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,$logo_qr_height, $logo_width, $logo_height);
    }
    //输出图片
    imagepng($QR, 'qrcode.png');
    imagedestroy($QR);
    imagedestroy($logo);
    return '<img src="qrcode.png" alt="使用微信扫描支付">';
    }
    使用方法也是一样。
  • 相关阅读:
    下拉菜单的option的value属性值问题
    GDAL1.9.1 IN VS2008 C#中的编译及使用
    多表连接 去重
    【示例代码】HTML+JS 画图板源码分享
    Winet API 支持HTTPP/SOCKS代理
    入门Html
    关于CDC在非控件类中的使用
    The document "ViewController.xib" could not be opened. Could not read archive.
    华为的一道题
    [置顶] WEBSOKET服务器搭建
  • 原文地址:https://www.cnblogs.com/Ares0023/p/10375411.html
Copyright © 2011-2022 走看看