tp6 给图片添加图标、文字水印

如果要给tp6上传图片之前给图片增加图片水印或者文字水印,必须使用composer安装图像处理类库

composer require topthink/think-image

安装之后后台的代码逻辑如下:

$files = $_FILES[\'file\'];
$name = $files[\'name\'];
$format = strrchr($name, \'.\');//截取文件后缀名如 (.jpg)
$file_path = \'uploads/images/\'.date(\'Ymd\').\"/\".sha1(date(\'YmdHis\', time()) . uniqid()) . $format;//保存路径
$image = \\think\\Image::open($files[\'tmp_name\'])->text(\'manongw.com\',root_path().\'/public/static/common/text/simhei.ttf\',20,\'#000000\')->save($file_path);  //添加文字水印
$image = \\think\\Image::open($files[\'tmp_name\'])->water(root_path().\'/public/static/common/images/water.png\',9,80)->save($file_path);  //添加图片水印

是不是很简单?

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容