PHP 图片、文字合成

//查询用户信息
$client = $this->where(array('id' => $client_id))->find();
        $client_avatar = $client['avatar'];
        $mine_code = $client['mine_code'];
        $have_code = is_file(SYS_ROOT_PATH . "uploadfiles/qrcode/{$mine_code}.png");
        //已经合成的不再重复生成
        if (!$have_code) {
        //生成原始二维码图
            $qrcode = sys_get_qrcode(SYS_ROOT . "index.php/Webservice/V100/register/mine_code/{$mine_code}", "uploadfiles/qrcode/{$mine_code}.png");//网络路径
            //原始二维码图的绝对路径
            $codeRealPath = SYS_ROOT_PATH . "uploadfiles/qrcode/{$mine_code}.png";
            $logo = SYS_ROOT_PATH . "uploadfiles/qrcode-min.png";//准备好的模板图片
            if ($qrcode) {
                $QR = $codeRealPath;//已经生成的原始二维码图
                $QR = imagecreatefromstring(file_get_contents($QR));
                $logo = imagecreatefromstring(file_get_contents($logo));
                $QR_width = imagesx($QR);//二维码图片宽度
                $QR_height = imagesy($QR);//二维码图片高度

                //图片合成
                imagecopyresampled($logo, $QR, 320, 1948, 0, 0, 445, 445, $QR_width, $QR_height);
                //保存到codeRealPath(路径)
                imagepng($logo, $codeRealPath);

                $path = $codeRealPath;

                if ($client['nickname']) {
                    $img = imagecreatefromstring(file_get_contents($path));
                    //字体类型
                    $font = SYS_ROOT_PATH . "uploadfiles/font/wenrui.otf";
                    //显示的文字
                    $text = '我是' . $client['nickname'];           
                    //设置字体颜色
                    $black = imagecolorallocate($img, 255, 255, 255);
                    imagettftext($img, 26, 0, 470, 1890, $black, $font, $text);
                    imagepng($img, $path);
                }

                //合成头像
                if ($client_avatar && $client_avatar != '') {
                    $member_avatar = imagecreatefromstring(file_get_contents($client_avatar));
                } else {
                    $member_avatar = imagecreatefromstring(file_get_contents(SYS_ROOT_PATH . "uploadfiles/default_avatar.png"));
                }

                $img = imagecreatefromstring(file_get_contents($path));
                imagecopyresampled($img, $member_avatar, 500, 2125, 0, 0, 85, 85, imagesx($member_avatar), imagesx($member_avatar));
                imagepng($img, $path);
            }
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值