PHP生成带logo,底部带文字的二维码

PHP如果想要生成logo,需要下载一个phpqrcode,我使用的版本是1.1.4版本的。各位看官可以自行百度下载

/**
     * 生成带logo的二维码
     * @param string $url
     * @param string $filename_1
     * @param string $text
     * @param string $logo2
     * @return string
     */
    function erweima($url='',$filename_1 = 'default',$text = '',$logo2 = ''){
        require_once __DIR__ . '/../../../vendor/phpqrcode/phpqrcode.php';
        $value = $url;         //二维码内容
        $errorCorrectionLevel = 'H';  //容错级别
        $matrixPointSize = 10;      //生成图片大小
        //生成二维码图片
        $filename = './static/qrcode/'.$filename_1.'.png';
        \QRcode::png($value,$filename , $errorCorrectionLevel, $matrixPointSize, 3);
        $QR2 = $filename;
        $QR = imagecreatefromstring(file_get_contents($QR2));    //目标图象连接资源。
        $QR_width = imagesx($QR);      //二维码图片宽度
        $QR_height = imagesy($QR);     //二维码图片高度
        $font = __DIR__ . '/../../../vendor/phpqrcode/fonts/open_sans.ttf'; // 字体文件
        //imagettftext只认utf8字体,所以用iconv转换
        $color = imagecolorallocate($QR, 0, 0, 0);
        $text_height = ($QR_height-5);
        $text_width = ($QR_width/2-35);
        imagettftext($QR, 21, 0, $text_width, $text_height, $color, $font, $text);//调二维码中字体位置
        $logo = imagecreatefromstring(file_get_contents($logo2));  //源图象连接资源。
        $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左上角所在坐标点
        $back_color = imagecolorallocate($QR, 255, 255, 255);//logo背景颜色
        imagefilledellipse($QR,($from_width+43),($from_width+43),100,100,$back_color);//调整圆形logo
        imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,$logo_qr_height, $logo_width, $logo_height);
        imagepng($QR, $filename);
        imagedestroy($QR);
        imagedestroy($logo);
        return $filename_1;
    }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值