2.0.0 • Published 2 years ago

watermark-for-vue v2.0.0

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

安装

npm install watermark-for-vue

使用方式

import Watermark from "watermark-for-vue";
export default {
  name: "App",
  components: {
    Watermark,
  },
  data() {
    return {
      options: {
        content: "",
      },
    };
  },
};
<watermark :options="options">
    <div class="container">
      内容区域
    </div>
</watermark>

注意事项

默认使用文字填充水印,当传入 src 时水印内容为图片水印,优先级高于文字水印。

options: {
  src: require("@/assets/logo.png");//https://avatars.githubusercontent.com/u/58333667?s=60&v=4
}

options 配置

属性说明类型默认值
widthcanvas元素宽string 300
heightcanvas元素高string 200
textAlign绘制文本的对齐方式stringleft
textBaseline文本基准线stringbottom
font字体大小及样式string16px Microsoft Yahei
fillStyle自定义水印的颜色stringblack
content水印内容string内部文档,请勿外传
globalAlpha设置图形和图像透明度的值number0.1
rotate旋转角度number16
repeat水印重复属性stringrepeat
xcanvas 横向偏移量number15
ycanvas 纵向偏移量number15
src水印为图片时的路径(支持本地和网络图片)stringnull
sx开始剪切的 x 坐标位置number0
sy开始剪切的 y 坐标位置number0
dx在画布上放置图像的 x 坐标位置number0
dy在画布上放置图像的 y 坐标位置number0
iwidth要使用的图像的宽度。(伸展或缩小图像)number60
iheight要使用的图像的高度。(伸展或缩小图像)number60
//canvas绘制图片水印的参数
ctx.drawImage(img, sx, sy, img.width, img.height, dx, dy, iwidth, iheight);

兼容性

使用了MutationObserver API,低版本浏览器无法使用,自行查看

2.0.0

2 years ago

1.1.0

3 years ago

1.0.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago