alimask 是一个使用canvas生成类似阿里巴巴内部网站水印图片的JavaScript库。Onlinedemo here.
1.Installnpminstallalimask
Thenimportit.
<script type="text/javascript" src="dist/alimask.min.js"></script>// orvar alimask = require('alimask');// orimport alimask from 'alimask';Thenuse alimask(text,options) API.
alimask('王小为(小为) 888888');alimask('王小为(小为) 888888', { color: '#f6dcd7' });alimask('小泥巴(小美) 888888', { alpha: 0.5 });2.APITheuniqueAPIis: alimask(text,options).
text (String):required,thetextinthewatermarkimage.
options (Object):optional,theoptionsofwatermark,withkeysbelow:
width (Number):defaultis 250.
height (Number):defaultis 80.
color (String):thetextcolor,defaultis #ebebeb.
alpha (Float):thetextalpha(0~1),defaultis 0.8.
font (String):thetextfontstyle,defaultis 10pxArial.
Theapireturn thebase64stringofwatermarkimage whichcanbeusedincssbackground/imgtag.
3.Build&Testnpminstall
npmrunbuild
npmtest
评论