zoukankan      html  css  js  c++  java
  • PHP生成二维码----phpqrcode

    phpqrcode类文件下载,下载地址:https://sourceforge.net/projects/phpqrcode/

    源码:

    function QRcode($url='') {
    require_once 'phpqrcode/phpqrcode.php';
    $value = $url; //二维码内容
    $errorCorrectionLevel = 'L'; //容错级别
    $matrixPointSize = 6; //生成图片大小
    //生成二维码图片
    $filename = 'qrcode/'.microtime().'.png';
    QRcode::png($value,$filename , $errorCorrectionLevel, $matrixPointSize, 2);

    $logo = 'data/img992.jpg'; //准备好的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, 'data/qrcode.png');
    imagedestroy($QR);
    imagedestroy($logo);
    return '<img src="qrcode.png" alt="使用微信扫描支付">';
    }

    //调用查看结果
    echo QRcode('https://www.baidu.com');
  • 相关阅读:
    bootmgr is missing
    【转】ahci和IDE的区别
    win10系统故障代码:0xc000014c
    c++小数点后舍入
    关于类里再声明自身类实例的思考
    Java集合
    Python图片转字符画
    102. Binary Tree Level Order Traversal
    1041. Robot Bounded In Circle
    144. Binary Tree Preorder Traversal
  • 原文地址:https://www.cnblogs.com/Bhi9712/p/9741836.html
Copyright © 2011-2022 走看看