npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@sangtian152/watermark

v1.0.9

Published

图片加文字水印、图片水印,支持多行

Readme

OSCS Status

介绍

图片加水印,支持文字水印、图片水印,支持多行

安装

npm install @sangtian152/watermark --save
# or 
yarn add @sangtian152/watermark

使用

import watermark from '@sangtian152/watermark';

const can = new watermark(url, options);
can.addText('文字水印', {repeat: true, lineSpacing: 146, markSpacing: '50%' })
can.addText('测试水印居中', {repeat: false, fontSize: 36, position: {right: '50%', bottom:  '50%'}, translate: '50%,50%'})
can.addImage(mark, {repeat: true, markHeight: 26, lineSpacing: 146, start: 36})
can.draw(function() {
    console.log('水印设置成功')
    const img = can.getBase64()
})

参数

| 参数 | 说明 | 类型 | 可选值 | 默认值 | |---------- |-------- |---------- |------------- |-------- | | url | 要添加水印的图片地址 | String | — | — | | options | 全局配置参数,详见options | Object | — | — |

方法

| 名称 | 说明 | 参数 | |---------- |-------- |---------- | | addText | 添加文字水印 | text, options(当前水印配置参数) | | addImage | 添加图片水印 | url, options(当前水印配置参数) | | draw | 绘制图片,在addText/addImage之后调用 | callback:Function | | getBase64 | 获取图片base64地址,需在draw方法的回调函数内调用 | —— | | getBlob | 获取Blob对象,需在draw方法的回调函数内调用 | —— | | getFile | 获取File对象,需在draw方法的回调函数内调用 | —— |

options

| 参数 | 说明 | 类型 | 可选值 | 默认值 | |---------- |-------- |---------- |------------- |-------- | | clip | 添加水印区域,如:{type: 'rect', padding: '10%'},type形状,可选值rect和circle,padding边距(参考css中padding用法),接受数组或逗号(,)隔开的字符串,支持百分数和数字 | Object | — | — | | defineClip | 自定义水印区域,参数为canvas的context对象,支持调用canvas原生方法,绘制任意形状水印区域 | Function | — | — | | fontSize | 文字水印字体大小 | Number | — | 26 | | fillStyle | 文字水印字体颜色 | String | — | #ffffff | | globalAlpha | 水印透明度 | Number | 0-1之间小数 | 0.2 | | position | 水印位置 | Object | — | {left: 10, top: 10} | | crossOrigin | 是否开启跨域(需后端支持) | Boolean | — | false | | translate | 水印根据给定的参数,从当前元素位置移动 | String/Array | — | 0 | | repeat | 水印是否重复 | Boolean | — | false | | rotate | 水印旋转角度,repeat为true时有效 | Number | — | -45 | | start | 水印起始位置,repeat为true时有效 | Number | — | 0 | | markSpacing | 两个相邻水印间隔,repeat为true时有效 | Number/String | — | 50% | | lineSpacing | 两行相邻水印间隔,repeat为true时有效 | Number/String | — | 60 |

最新版本

NPM version