二维码生成及二维码背景设置

margin(1000)->merge($apath . '/logo.png', .3, true)->format('png')->size(250)->generate($location_url, $file_path);
        $this->remarkCode($file_path, $back_path, $seatRow, $company_name);
//        echo $redirect_domain . '/' . $url_path;
        return '/qrcode/' . $create_name;
//       $qrCode = new QrCode($location_url);
//       echo  $location_url;
        // echo $location_url =URL::secureAsset('index.php/wxcode/'.$code); exit;
//       echo URL::secureAsset($url_path);exit;

//       echo storage_path('codeImage');
//       $qrCode->size(298);
//       if($set_log ==true){
//           if(!empty($logo)){
//
//               $qrCode->setLogoPath($logo);
//           }
//
//           $qrCode->setLogoWidth(65);
//           $qrCode->setLogoHeight(65);
//       }
//       $path =$file_path.$file_name;
//
//       $qrCode->writeFile($path);
//       $code_path['code'] = URL::secureAsset($url_path);;
//        echo $code_path;exit;
//       return  $code_path;


    }


    function remarkCode($path, $path_remark, $seatRow, $company_name)
    {
        $code = $path;
        $font_msyh = storage_path('app/public/simhei.ttf');
//        $dst = storage_path('codeImage/bgf.png');
        $dst = storage_path('codeImage/bg_code.jpg');
        $dst_logo = storage_path('codeImage/bg_logo.png');
        $codes = imagecreatefrompng($code);
        $dst_im = imagecreatefromjpeg($dst);
        $dst_logo = imagecreatefrompng($dst_logo);

//        $height = 450;
//
//        $width = 368;
//        $im = imagecreatetruecolor($width, $height);  //创建一张与背景图同样大小的真彩色图像
//        $green = imagecolorallocate($im, 255, 0, 255);
//3. 使用绿色填充画布
//        imagefill($im, 0, 0, $green);
        $width_bg = imagesx($dst_im);
        $height_bg = imagesy($dst_im);
        $width_code = imagesx($codes);
        $height_code = imagesy($codes);
//        $width_logo = imagesx($dst_logo);
//        $height_logo = imagesy($dst_logo);
//        $color_black = ImageColorAllocate($im, 000, 000, 000);
                $color_black = ImageColorAllocate($dst_im, 000, 000, 000);

        $fontSize = 18; //18号字体
//        $font_way = ($width_bg-imagefontwidth(35)*4)/2;
//        echo mb_strlen('阿萨大123a');exit;
//     echo   $fontWidth = imagefontwidth($fontSize);
//        echo $this->text_height($fontSize, $font_msyh,'我撒旦');
//        $company__width =  $this->text_width($fontSize, $font_msyh,$company_name);
//        $clogow = ($width_bg-($company__width+$width_logo))/2;
//        $company_x = $clogow+$width_logo;
//     exit;
//
//        imagettftext($im, $fontSize, 0,30, 60, $color_black, $font_msyh, '扫码点餐');
//        imagecopymerge($im, $codes, ($width-$width_code)/2, 80, 0, 0, $width_code, $height_code, 100);
        imagecopymerge($dst_im, $codes, ($width_bg - $width_code) / 2, 25, 0, 0, $width_code, $height_code, 100);
//        imagecopymerge($dst_im, $dst_logo, ($width_bg - $width_code) / 2, 75 + $height_code + 50 + 50 + 50, 0, 0, $width_logo, $height_logo, 100);
//        imagecopymerge($dst_im, $dst_logo, $clogow, 75 + $height_code + 50 + 50 + 50, 0, 0, $width_logo, $height_logo, 100);

//        imagettftext($dst_im, 35, 0, ($width_bg - $width_code) / 2 + 10, 75 + $height_code, $color_black, $font_msyh, '扫码点餐');
//        imagettftext($dst_im, 35, 0, ($width_bg - $width_code) / 2 + 10, 75 + $height_code + 50, $color_black, $font_msyh, '在线服务');
        $seatWidth = $this->text_width(20, $font_msyh,$seatRow);
        $seat_x = ($width_bg-$seatWidth)/2;
        imagettftext($dst_im, 20, 0, $seat_x, $height_code +150, $color_black, $font_msyh, $seatRow);

//        imagettftext($dst_im, 20, 0, ($width_bg - $width_code) / 2 + 10 + 20, 75 + $height_code + 50 +25, $color_black, $font_msyh, $seatRow);
//        imagettftext($dst_im, 20, 0, ($width_bg - $width_code) / 2 + 10 + 20, 75 + $height_code + 50 + 50 + 50, $color_black, $font_msyh, $company_name);
//        imagettftext($dst_im, 20, 0, $company_x, 75 + $height_code + 50 + 50 + 50, $color_black, $font_msyh, $company_name);
//        imagecopymerge($im, $dst_im, 0, 0, 0, 0, 1000, 450, 100);
//
//        imagecopymerge($im, $codes, ($width-$width_code)/2, 80, 0, 0, $width_code, $height_code, 100);
//

        header('Content-Type: image/png');
//        imagejpeg($im,$path_remark);  //浏览器直接显示
        imagejpeg($dst_im, $path_remark);  //浏览器直接显示

        // echo 22222;
    }


    function get_bbox($size,$font,$text){
        return imagettfbbox($size, 0, $font, $text);
    }
//获取文字高度
    function text_height ($size,$font,$text) {
        $box = $this->get_bbox($size,$font,$text);
        $height = $box[3] - $box[5];
        return $height;
    }
//获取文字宽度
    function text_width ($size,$font,$text) {
        $box = $this->get_bbox($size,$font,$text);
        $width = $box[4] - $box[6];
        return $width;
    }
}

 

你可能感兴趣的:(php)