码迷,mamicode.com
首页 > 其他好文 > 详细

canvas添加水印

时间:2017-07-27 11:34:19      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:ase   image   get   line   fill   can   ddl   contex   sel   

<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添加水印

标签:ase   image   get   line   fill   can   ddl   contex   sel   

原文地址:http://www.cnblogs.com/founderswitch/p/7243702.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!