1、将下载好的字体引入至 thinkPHP 框架的public/static 下(这里我建了一个文件夹叫font)

(1.)

think php 图像加水印_搜索

 

 (2.)

think php 图像加水印_搜索_02

 

 
2.将字体路径写入config.php中
    'font'=>ROOT_PATH.'/public/static/font/simhei.ttf',

think php 图像加水印_php_03

 

 3.(结合上一篇think php 增删改查搜索 ,标红){控制器save方法}) 

  public function save(Request $request)
    {
        //
        $params = $request->param();
        $file = $request->file('img');
//验证图片
        if ($file) {
            $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
            if ($info) {
//                string(45) "20210820\0fd2d7bea8a34235624d83e914780248.gif"
                $filename = DS . 'uploads' . DS . $info->getSaveName();//
                $image = \think\Image::open('.' . $filename);

                $fontpath=config('font');
                $image->text('今天是个好日子',$fontpath,'20','#79FF79')->save('.' . $filename);
//替换
                $params['img'] = $filename;
            } else {
                // 上传失败获取错误信息
                echo $file->getError();
            }
        }

think php 图像加水印_php_04

 4.效果图

think php 图像加水印_上传_05