美文网首页
phpGD 合成图片+文字

phpGD 合成图片+文字

作者: observerb | 来源:发表于2019-02-20 15:06 被阅读4次

public function qr_br_img(){

        if(!empty($this->request->get['friendcode'])){

            $token=$this->request->get['friendcode'];

            $tokennum=trim(substr($token,32));

        }else{

            $token='';

            $tokennum='';

        }

        if(!empty($this->request->get['name'])){

            $name=$this->request->get['name'];

        }else{

            $name='';

        }

        if(!empty($this->request->get['phone'])){

            $phone=$this->request->get['phone'];

        }else{

            $phone='';

        }

        if(!empty($this->request->get['vipcard'])){

            $vipcard=$this->request->get['vipcard'];

        }else{

            $vipcard='';

        }

        //图片水印

        $mark_filename = 'https://txh.eeeeasy.com/index.php?route=txh/person/shepima&token=6666666666666666666666666666666688';

        $info = getimagesize($mark_filename);

        //获取图片的后缀

        $type = image_type_to_extension($info[2], false);

        //拼接图片资源句柄函数

        $func = 'imagecreatefrom'.$type;

        //创建图片资源句柄

        $image = $func($mark_filename);

        //裁剪图片的大小为原图的4分之一

        $w = $info[0]/2;

        $h = $info[1]/2;

        $mark_image = imagecreatetruecolor($w, $h);

        //裁剪

        imagecopyresampled($mark_image, $image, 0, 0, 0, 0, $w, $h,

            $info[0], $info[1]);

        //销毁内存

        imagedestroy($image);

        //需要加水印的图片

        $filename = $_SERVER['DOCUMENT_ROOT'].'/bg.png';

        $mark = getimagesize($filename);

        $mark_type = image_type_to_extension($mark[2], false);

        //创建图片资源句柄

        $mark_func = 'imagecreatefrom'.$mark_type;

        $image = $mark_func($filename);

        //合并,添加水印图片

        imagecopymerge($image, $mark_image, 20, 30, 0,0, $w, $h, 00);

        //销毁内存

        imagedestroy($mark_image);

        //文字水印

        $font = $_SERVER['DOCUMENT_ROOT']."/msyh.ttf";

        $content = $name."\n手機號碼:".$phone."\n會卡號:".$vipcard."\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n                        我的二維碼";

        $col = imagecolorallocatealpha($image, 0, 0, 0, 0);

        //imagettftext介绍:(第一个参数:画布,第二个参数:字体大小,第三个参数:字型的角度,0为水平,第四个参数:X坐标,第五个参数:Y坐标,第六个参数:字体颜色,第七个参数:字体,第八个:文字内容

        imagettftext($image, 10, 0, 20, 75, $col, $font, $content);

        //图片输出函数拼接

        $outFunc = 'image'.$type;

        // echo 'uploading/qr_br_img/img'.$tokennum.'.'.$type;exit;

        //保存图片

        $outFunc($image, 'uploadimg/qr_br_img/img'.$tokennum.'.'.$type);

        // imagejpeg($image,'1.jpg');

        //输出到浏览器

        // header("Content-Type:".$info['mime']);

        // $outFunc($image);

        //輸出條形碼二維碼

        $bigImgPath = 'uploadimg/qr_br_img/img'.$tokennum.'.'.$type;

        $qCodePath = 'https://txh.eeeeasy.com/index.php?route=txh/person/shepima&token='.$token;

        $qCodePath2 = 'https://txh.eeeeasy.com/index.php?route=txh/person/shepitiao&token='.$token;

        $bigImg = imagecreatefromstring(file_get_contents($bigImgPath));

        $qCodeImg = imagecreatefromstring(file_get_contents($qCodePath));

        $qCodeImg2 = imagecreatefromstring(file_get_contents($qCodePath2));

        /*  */

        $qCodeImg2 = imagecreatefromstring(file_get_contents($qCodePath2));

        /*  */

        list($qCodeWidth, $qCodeHight, $qCodeType) = getimagesize($qCodePath);

        imagecopymerge($bigImg, $qCodeImg, 100, 260, 0, 0, $qCodeWidth, $qCodeHight, 100);

        list($qCodeWidth, $qCodeHight, $qCodeType) = getimagesize($qCodePath2);

        // imagecopymerge使用注解

        imagecopymerge($bigImg, $qCodeImg2, 10, 135, 0, 0, $qCodeWidth, $qCodeHight, 100);

        list($bigWidth, $bigHight, $bigType) = getimagesize($bigImgPath);

        switch ($bigType) {

            case 1: //gif

                header('Content-Type:image/gif');

                imagegif($bigImg);

                break;

            case 2: //jpg

                header('Content-Type:image/jpg');

                imagejpeg($bigImg);

                break;

            case 3: //jpg

                header('Content-Type:image/png');

                imagepng($bigImg);

                break;

            default:

                # code...

                break;

        }

        imagedestroy($bigImg);

        imagedestroy($qcodeImg);

    }

相关文章

网友评论

      本文标题:phpGD 合成图片+文字

      本文链接:https://www.haomeiwen.com/subject/pyzjdqtx.html