身份证水印

<html>
<head>
<style>
canvas { margin:auto; display:block; }
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script>
var canvas = document.getElementById('canvas');
var a = 6;
canvas.width = 210 * a;
canvas.height = 297 * a;
var ctx = canvas.getContext('2d');
ctx.fillStyle = 'white';
ctx.fillRect(0,0,canvas.width,canvas.height);
ctx.font = '30px Arial';
var dx = Math.random()*200;
var dy = Math.random()*200;	

var img1 = new Image();
img1.src = 'sfz1.jpg';
img1.onload = function() { draw(); };

var img2 = new Image();
img2.src = 'sfz2.jpg';
img2.onload = function() { draw(); };

function draw() {
	if (img1.complete && img2.complete) {
		var dw = 85.6 * a;
		var dh = 54 * a;
		ctx.drawImage(img1, canvas.width/2 - dw/2, canvas.height / 2 - 1.5 * dh, dw, dh);
		ctx.drawImage(img2, canvas.width/2 - dw/2, canvas.height / 2 + 0.5 * dh, dw, dh);
		
		ctx.save();
		ctx.fillStyle = 'gray';
		ctx.rotate(-Math.PI/4);
		var t = '劳动能力鉴定';
		var tw = ctx.measureText(t).width;
		for (x=-canvas.width; x<canvas.width; x+=2*tw) {
			for (y=0; y<1.5*canvas.height; y+=tw) {				
				ctx.fillText(t, x + dx, y + dy);
			}
		}
		ctx.restore();
	}	
}
</script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值