给二维码(图片)添加文字(水印),让生成的二维码中间带logo

<?php
//生成二维码
    require_once IA_ROOT . '/framework/library/qrcode/phpqrcode.php';
    QRcode::png($url, $qrcode_file, QR_ECLEVEL_L, 4);

注: $url:二维码内容
    $qrcode_file:二维码存放路径


//生成的二维码,添加水印
    $font = "/var/www/swoole/ttf/msyh.ttf";//必须绝对路径
    $file = 'image/2.png';

    $info = getimagesize($file);                          // 获取图片信息
    $type = image_type_to_extension($info[2],false);      // 获取图片扩展名
    $fun  = "imagecreatefrom{$type}";                     // 构建处理图片方法名-关键是这里
    $img = $fun($file);                                   // 调用方法处理
    $red = imagecolorallocate($img, 255, 0, 0);
    $sting = '添加水印';
    imagettftext($img, 10, 0, 30, 80, $red, $font, $sting);
    imagepng($QR, $file);  
    
    header("Content-type: image/gif; charset=utf-8");
    imagegif($img);

 // 让生成的二维码中间带logo  
    
    $logo = 'logo.jpg';
    $QR  = 'image/2.png';
     
    $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 / 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, 'image/2.png');