• php背景图片上生成二维码,二维码上带logo 代码示例 (原)


    依赖库文件 phpqrcode.php

    (下载地址://www.jb51.net/codes/189897.html ;或者在官网下载:http://phpqrcode.sourceforge.net )

    本地演示文件代码下载(装环境即可)

    百度网盘链接:https://pan.baidu.com/s/1L4dExJIJhbjrNa-hBrrdzg 密码:dmvs

    代码逻辑:
    1.生成一张url相关的 二维码 QR
    2.把log图片跟QR合并成一个带logo的二维码 last
    3.把带logo的的二维码跟 活动图片合成为一张图 保存到本地或直接输出图片

    <?php 
    /**
     * 生成管理员分销二维码
     * ============================================================================
     * ============================================================================
     * $Author: 戈丫汝 QQ:534208139
     * 2018-11-9 17:20:08Z
     */
    require_once("./phpqrcode/phpqrcode.php");
    //参数 活动模板图片,二维码url,模板内二维码的位置


    $mes = getActivityImg('./images/123.png','http://shop.izhiwo.com',258,273);
    print_r($mes);die;
    function getActivityImg($template,$url,$x,$y)
    {
          //二维码中间添加logo
          $logo = './images/logo.png';
          $QR = "base.png";
          $last = "last.png";
          $errorCorrectionLevel = 'Q'; //防错等级
          $matrixPointSize = 3; //二维码大小

          //生成二维码
          //参数内容:二维码储存内容,生成存储,防错等级,二维码大小,白边大小
          QRcode::png($url, $QR, $errorCorrectionLevel, $matrixPointSize, 1);

          //合并logo跟二维码
          $QR = imagecreatefromstring(file_get_contents($QR));
          $logo = imagecreatefromstring(file_get_contents($logo));
          $QR_width = imagesx($QR); $logo_width = imagesx($logo);
          $logo_height = imagesy($logo);
          $logo_qr_width = $QR_width / 5;
          $scale = $logo_width / $logo_qr_width;
          $logo_qr_height = $logo_height / $scale;
          $from_width = ($QR_width - $logo_qr_width) / 2;
          imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
          imagepng($QR,$last); // 生成带log的二维码图片 存储到last


          //合成带logo的二维码图片跟 模板图片
          $path_1 = $template; //背景图
          $path_2 = $last;  //带logo的二维码图
          $dst = imagecreatefromstring(file_get_contents($path_1));
          $src = imagecreatefromstring(file_get_contents($path_2));
          list($src_w, $src_h) = getimagesize($path_2);
          imagecopymerge($dst, $src, $x, $y, 0, 0, $src_w, $src_h, 100);
          list($dst_w, $dst_h, $dst_type) = getimagesize($path_1);
          
          //第一种:图片输出到页面
          /*switch ($dst_type) {
            case 1://GIF
                header('Content-Type: image/gif');
                imagegif($dst);
                break;
            case 2://JPG
                header('Content-Type: image/jpeg');
                imagejpeg($dst);
                break;
            case 3://PNG
                header('Content-Type: image/png');
                imagepng($dst);
                break;
            default:
                break;
        }
        imagedestroy($dst);
        imagedestroy($src);*/

         //第二种:输出到本地文件夹,返回生成图片的路径
         $fileName= md5(rand(0,999));
         $EchoPath='./images/'.$fileName.'.png';
         imagepng($dst,$EchoPath);
         imagedestroy($dst);
         return $EchoPath;
    }

     时间:2019-03-31    新增代码 (需求:生成后的图片加文字)

    以下代码放到输出图片代码前即可,其他不变,全部代码文字位置二维码位置都没有调试,需要的可以根据自己需求调试. END~~~

         
    //打上文字 $font = 'simsun.ttc'; //字体 $black = imagecolorallocate($dst, 0x00, 0x00, 0x00); //字体颜色 imagefttext($dst, 13, 0, 20, 20, $black, $font, " 快乐编程快乐编程快乐 编程快乐编程快乐编程快乐编程快乐编程 编程快乐编程快乐编程快乐编."); //输出图片 list($dst_w, $dst_h, $dst_type) = getimagesize($path_1);
  • 相关阅读:
    C语言编译包含math库加参数-lm
    C语言浮点类型有效位(float, double,long double)
    C语言速记(宏)
    C语言速记6(结构体)
    asp.net Core依赖注入汇总
    跨域请求(转载)
    UnobtrusiveJavaScriptEnabled、ClientValidationEnabled(转载)
    到值类型“System.DateTime”的强制转换失败,因为具体化值为 null。结果类型的泛型参数或查询必须使用可以为 null 的类型。
    软件开发PPT中造图片软件:ProcessOn
    EF接收数据通用实体模型
  • 原文地址:https://www.cnblogs.com/gyrgyr/p/9923564.html
Copyright © 2020-2023  润新知