Skip to content

WatermarkPlugin — 水印

优先级:20

支持文字水印和图片水印,5 个预设位置,可自定义透明度与样式。

基础用法

文字水印

ts
import { WatermarkPlugin } from "@file-ud.js/plugins/uploader";

uploader.use(new WatermarkPlugin({
  text: "© MyCompany",
  position: "bottom-right",
  opacity: 0.6,
}));

图片水印

ts
import { WatermarkPlugin } from "@file-ud.js/plugins/uploader";

uploader.use(new WatermarkPlugin({
  imageUrl: "https://example.com/logo.png",
  position: "top-left",
  imageWidth: 100,
  imageHeight: 100,
}));

配置参数

参数类型默认值说明
textstring水印文字
imageUrlstring水印图片 URL
positionstring"center"位置:center / top-left / top-right / bottom-left / bottom-right
opacitynumber0.5透明度,0 - 1
imageWidthnumber图片水印宽度(px)
imageHeightnumber图片水印高度(px)

注意textimageUrl 二选一。同时提供时,优先使用 imageUrl

使用场景

品牌保护

ts
uploader.use(new WatermarkPlugin({
  imageUrl: "/brand-logo.png",
  position: "bottom-right",
  imageWidth: 120,
  imageHeight: 40,
  opacity: 0.7,
}));

版权声明

ts
uploader.use(new WatermarkPlugin({
  text: "© 2024 All Rights Reserved",
  position: "center",
  opacity: 0.3,
}));

角标水印

ts
uploader.use(new WatermarkPlugin({
  text: "预览版",
  position: "top-right",
  opacity: 0.5,
}));

基于 MIT 协议发布