来源: 本站版本: (PHP)JTBC3.0
J3上传图片添加水印教程
本教程以case模块为例.仅支持模块中上传图片和编辑器下方附件上传图片添加水印.
1.模块中添加水印配置
打开\case\common\config.JTBC
添加节点
<item>
<name><![CDATA[upload_watermark]]></name>
<zh-cn><![CDATA[1]]></zh-cn>
</item>
<item>
<name><![CDATA[upload_watermark_path]]></name>
<zh-cn><![CDATA[common/assets/upload/watermark.png]]></zh-cn>
</item>
<item>
<name><![CDATA[upload_watermark_limit]]></name>
<zh-cn><![CDATA[{"origin":"-1","x":"100","y":"100"}]]></zh-cn>
</item>
其中upload_watermark节点为水印开关,1为启用水印,0为关闭水印
其中upload_watermark_path节点为模块文件夹中的水印图片位置
其中upload_watermark_limit节点中"origin":"-1"为控制水印位置,居中-1,左上0,右上1,左下2,右下3
"x":"100","y":"100"为控制距离,注意:设置水印位置-1居中时无效.
2.准备一样图片watermark.png作为水印
上传到case/common/assets/upload/文件夹中
或者自行选择放置位置,只需修改1中的upload_watermark_path节点内容即可.
3.修改上传代码,添加处置函数
打开/common/incfiles/lib/jtbc/universal/upload2self.inc.php文件
找到代码(大概158行)
image::resizeImage($uploadFullPath, $uploadFullPath, $resizeWidth, $resizeHeight, $resizeMode, 0, $resizeQuality);
}
替换成
image::resizeImage($uploadFullPath, $uploadFullPath, $resizeWidth, $resizeHeight, $resizeMode, 0, $resizeQuality);
}
$watermark = base::getNum(tpl::take('config.upload_watermark', 'cfg'), 0);
$watermarkImageFilePath = tpl::take('config.upload_watermark_path', 'cfg');
$watermarkImageFileLimit = tpl::take('config.upload_watermark_limit', 'cfg');
$watermarkImageFileLimitAry = null;
if (!base::isEmpty($watermarkImageFileLimit)) $watermarkImageFileLimitAry = json_decode($watermarkImageFileLimit, true);
if(!empty($watermarkImageFileLimitAry)){
$watermarkOrigin = base::getNum($watermarkImageFileLimitAry['origin'], 0);
$watermarkX = base::getNum($watermarkImageFileLimitAry['x'], 0);
$watermarkY = base::getNum($watermarkImageFileLimitAry['y'], 0);
}
if($watermark == 1)image::watermarkImage($uploadFullPath, $uploadFullPath, $watermarkImageFilePath,$watermarkOrigin,$watermarkX,$watermarkY);//水印函数,处理后的图片添加水印
4.注意事项
配置好后,清除缓存,上传图片可以看到效果
水印图片尺寸建议宽度150px左右.具体尺寸可以自行调整.
技术支持QQ:925474725