canvas添加水印
Posted Mr.方
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了canvas添加水印相关的知识,希望对你有一定的参考价值。
<canvas id="canvas"></canvas>
<canvas id="water"></canvas>
<img src="" id="imgShow" />
var ca = document.getElementById("canvas");
var ctx = ca.getContext("2d");
var water = document.getElementById("water");
var waterCtx = water.getContext("2d");
var imgShow = document.getElementById("imgShow");
ca.width = 900;
ca.height = 600;
water.width = 200;
water.height = 50;
var img = new Image();
img.src = "img.jpg";
// 水印canvas的样式
waterCtx.font = "30px Aril bold";
waterCtx.fillStyle = "rgba(0,0,0,.3)";
waterCtx.textBaseline = "midddle";
waterCtx.fillText("芳芳芳芳付", 20, 30);
// 图片加载完后,去执行其他操作
img.onload = function(){
ctx.drawImage(img,ca.width - img.width,ca.height - img.height);
ctx.drawImage(water,ca.width - water.width,ca.height - water.height);
var imgOut = ca.toDataURL("image/jpeg");
imgShow.src = imgOut;
}
以上是关于canvas添加水印的主要内容,如果未能解决你的问题,请参考以下文章