您的位置:首页 > Web前端 > JavaScript

JS添加文字水印

2016-09-24 18:59 465 查看
<html>
<script>
function watermark(str){
var img = document.getElementById("img");
var canvas=document.getElementById("cvs");
var ctx=canvas.getContext("2d");
ctx.drawImage(img,0,0);
ctx.font="20px microsoft yahei";
ctx.fillStyle = "rgba(255,255,255,0.5)";
ctx.fillText(str,100,100);
}
</script>
<canvas id="cvs" width="1000" height="500" >
Your browser does not support the HTML5 canvas tag.
</canvas>
<image id="img" src="test.png" > </image>
<button onclick="watermark('Hello world')">add watermark</button>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: