HTML5 Canvas 为网页添加文字水印

<!DOCTYPE html>
<html>
<body>

<canvas id="myCanvas" width="3000" height="1500" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.
</canvas>

<script>
var can = document.createElement('canvas');
var body = document.body;
body.appendChild(can);
can.width=400;
can.height=200;
can.style.display='none';
var cans = can.getContext('2d');
//ctx.translate(-60, 0);//移动坐标原点
cans.rotate(-20*Math.PI/180);
cans.font = "16px Microsoft JhengHei";
cans.fillText("阿斯顿发送到!",can.width/3,can.height/2);
body.style.backgroundImage="url("+can.toDataURL("image/png")+")";

</script>

</body>
</html>

 

posted @ 2019-09-29 12:01  Joye.Net  阅读(2152)  评论(0编辑  收藏  举报