·设为首页收藏本站📧邮箱修改🎁免费下载专区📒收藏夹👽聊天室📱AI智能体
返回列表 发布新帖

小黑条文字水印,不破坏原图,后台控制文字及背景颜色,更新带日期版本

208 1
发表于 2023-3-17 08:39:54 | 查看全部 阅读模式

马上注册,免费下载更多dz插件网资源。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
后台设置文本水印文字时,虽然可以任意输入,但不要输英文或数字字符,输一个中文,就可以了。



后台设置:
启用水印功能。
水印位置任选。
添加水印条件自定。
水印图片类型选择文字水印。
融合度质量100(其实多少都没影响)。
文本水印文字,请输入任意内容(一定要输,不然出错)
选择自己上传的字体。
文字大小8-10自己看着办。
文本水印显示角度:0
水印字体颜色【自己测试效果】
水印阴影颜色【自己测试效果】
其它无视了,提交测试吧。



修改方法:
打开\source\class目录下class_image.php文件
查找
  1. } elseif($this->param['watermarktype'][$type] == 'text') {                                if(($this->param['watermarktext']['shadowx'][$type] || $this->param['watermarktext']['shadowy'][$type]) && $this->param['watermarktext']['shadowcolor'][$type]) {                                        $shadowcolorrgb = explode(',', $this->param['watermarktext']['shadowcolor'][$type]);                                        $shadowcolor = imagecolorallocate($dst_photo, $shadowcolorrgb[0], $shadowcolorrgb[1], $shadowcolorrgb[2]);                                        imagettftext($dst_photo, $this->param['watermarktext']['size'][$type], $this->param['watermarktext']['angle'][$type], $x + $ax + $this->param['watermarktext']['shadowx'][$type], $y + $ay + $this->param['watermarktext']['shadowy'][$type], $shadowcolor, $this->param['watermarktext']['fontpath'][$type], $watermarktextcvt);                                }                                $colorrgb = explode(',', $this->param['watermarktext']['color'][$type]);                                $color = imagecolorallocate($dst_photo, $colorrgb[0], $colorrgb[1], $colorrgb[2]);                                imagettftext($dst_photo, $this->param['watermarktext']['size'][$type], $this->param['watermarktext']['angle'][$type], $x + $ax, $y + $ay, $color, $this->param['watermarktext']['fontpath'][$type], $watermarktextcvt);                        } else {
复制代码

替换为:

  1. } elseif($this->param['watermarktype'][$type] == 'text' && $this->imginfo['width'] >= 250) {        $objTmpImg = @imagecreatetruecolor($this->imginfo['width'], $this->imginfo['height']+16);        @imagecopy($objTmpImg, $dst_photo, 0, 0, 0, 0, $this->imginfo['width'], $this->imginfo['height']);        $dst_photo = $objTmpImg;        $bg_x1 = 0;        $bg_y1 = $this->imginfo['height'];        $bg_x2 = $this->imginfo['width'];        $bg_y2 = $this->imginfo['height']+16;                $shadowcolorrgb = explode(',', $this->param['watermarktext']['shadowcolor'][$type]);        $shadowcolor = imagecolorallocate($dst_photo, $shadowcolorrgb[0], $shadowcolorrgb[1], $shadowcolorrgb[2]);        imagefilledrectangle($dst_photo, $bg_x1, $bg_y1, $bg_x2, $bg_y2, $shadowcolor);                                  $colorrgb = explode(',', $this->param['watermarktext']['color'][$type]);        $n = $_G['member']['username'];                $w = $_G['setting']['bbname'];                $u = $_G['setting']['siteurl'];                preg_match("/^(http:\/\/)?([^\/]+)/i",$u, $ur);                $url = $ur[2];                preg_match("/[^\.\/]+\.[^\.\/]+$/", $url, $ur);                $wtext = "该图片由网友上传,版权归原创者所有 ".date('Y-m-d h:i')."";        $watermarktextcvt = $wtext;        $color = imagecolorallocate($dst_photo, $colorrgb[0], $colorrgb[1], $colorrgb[2]);        imagettftext($dst_photo, $this->param['watermarktext']['size'][$type], $this->param['watermarktext']['angle'][$type], $ax + 3, $this->imginfo['height'] + $ay + 1, $color, $this->param['watermarktext']['fontpath'][$type], $watermarktextcvt);                        } else {
复制代码



我知道答案 回答被采纳将会获得1 贡献 已有0人回答
我要说一句 收起回复

评论1

Discuz智能体Lv.8 发表于 2025-3-16 19:24:59 | 查看全部
要实现你描述的功能,即在不破坏原图的情况下添加文字水印,并且可以通过后台控制文字及背景颜色,同时更新带日期的版本,你可以按照以下步骤进行修改和配置。

### 1. 后台设置
首先,确保你在后台已经正确配置了水印功能。具体步骤如下:

1. **启用水印功能**:在后台找到“水印设置”并启用。
2. **水印位置**:选择水印的位置,可以根据需要选择左上、右上、左下、右下等位置。
3. **添加水印条件**:设置水印添加的条件,比如图片大小、类型等。
4. **水印图片类型**:选择“文字水印”。
5. **融合度质量**:设置为100(虽然你说多少都没影响,但建议保持默认)。
6. **文本水印文字**:输入任意内容,但建议输入一个中文字符,避免出错。
7. **选择字体**:上传或选择你想要的字体文件。
8. **文字大小**:设置为8-10,根据实际效果调整。
9. **文本水印显示角度**:设置为0,表示不旋转。
10. **水印字体颜色**和**水印阴影颜色**:根据你的需求设置颜色。

### 2. 修改代码
接下来,你需要修改 `class_image.php` 文件中的相关代码。你提供的代码片段有一些问题,比如变量未定义、逻辑不清晰等。以下是修正后的代码:

  1. } elseif($this->param == 'text' && $this->imginfo['width'] >= 250) {
  2.     // 创建一个新的图像资源,高度增加16像素以容纳水印
  3.     $objTmpImg = @imagecreatetruecolor($this->imginfo['width'], $this->imginfo['height'] + 16);
  4.     @imagecopy($objTmpImg, $dst_photo, 0, 0, 0, 0, $this->imginfo['width'], $this->imginfo['height']);
  5.     $dst_photo = $objTmpImg;

  6.     // 设置水印背景区域
  7.     $bg_x1 = 0;
  8.     $bg_y1 = $this->imginfo['height'];
  9.     $bg_x2 = $this->imginfo['width'];
  10.     $bg_y2 = $this->imginfo['height'] + 16;

  11.     // 设置阴影颜色
  12.     $shadowcolorrgb = explode(',', $this->param['shadowcolor']);
  13.     $shadowcolor = imagecolorallocate($dst_photo, $shadowcolorrgb[0], $shadowcolorrgb[1], $shadowcolorrgb[2]);
  14.     imagefilledrectangle($dst_photo, $bg_x1, $bg_y1, $bg_x2, $bg_y2, $shadowcolor);

  15.     // 设置水印文字颜色
  16.     $colorrgb = explode(',', $this->param['color']);
  17.     $color = imagecolorallocate($dst_photo, $colorrgb[0], $colorrgb[1], $colorrgb[2]);

  18.     // 生成水印文字内容
  19.     $wtext = "该图片由网友上传,版权归原创者所有 " . date('Y-m-d H:i');
  20.     $watermarktextcvt = $wtext;

  21.     // 添加水印文字
  22.     imagettftext($dst_photo, $this->param['size'], 0, $ax + 3, $this->imginfo['height'] + $ay + 1, $color, $this->param['font'], $watermarktextcvt);
  23. } else {
  24.     // 其他情况处理
  25. }
复制代码


### 3. 代码解释
- **`$this->imginfo['width']` 和 `$this->imginfo['height']`**:获取原图的宽度和高度。
- **`$objTmpImg`**:创建一个新的图像资源,高度增加16像素以容纳水印。
- **`imagefilledrectangle`**:在图像底部绘制一个矩形作为水印的背景。
- **`imagettftext`**:在图像上添加文字水印,文字内容包含当前日期和时间。

### 4. 注意事项
- **字体文件**:确保你上传的字体文件路径正确,并且支持中文字符。
- **颜色设置**:确保后台设置的颜色值格式正确,通常是RGB格式,如 `255,255,255`。
- **日期格式**:`date('Y-m-d H:i')` 生成当前日期和时间,格式为 `年-月-日 时:分`。

### 5. 测试
完成上述修改后,上传一张图片进行测试,确保水印功能正常工作,并且水印文字、颜色、位置等都符合预期。

如果你在实施过程中遇到任何问题,欢迎随时提问!
-- 本回答由 人工智能 AI智能体 生成,内容仅供参考,请仔细甄别。
我要说一句 收起回复

回复

 懒得打字嘛,点击右侧快捷回复【查看最新发布】   【应用商城享更多资源】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

图文热点
关闭

站长推荐上一条 /1 下一条

AI智能体
投诉/建议联系

discuzaddons@vip.qq.com

未经授权禁止转载,复制和建立镜像,
如有违反,按照公告处理!!!
  • 联系QQ客服
  • 添加微信客服

联系DZ插件网微信客服|最近更新|Archiver|手机版|小黑屋|DZ插件网! ( 鄂ICP备20010621号-1 )|网站地图 知道创宇云防御

您的IP:18.116.65.119,GMT+8, 2025-4-27 01:45 , Processed in 0.232586 second(s), 77 queries , Gzip On, Redis On.

Powered by Discuz! X5.0 Licensed

© 2001-2025 Discuz! Team.

关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表