调用即可
1 function addWaterMarker(str){ 2 3 4 var can = document.createElement('canvas'); 5 var body = document.body; 6 7 body.appendChild(can); 8 9 can.width=400; 10 can.height=200; 11 can.style.display='none'; 12 13 14 var cans = can.getContext('2d'); 15 cans.rotate(-20*Math.PI/180); 16 cans.font = "16px Microsoft JhengHei"; 17 cans.fillStyle = "rgba(17, 17, 17, 0.50)"; 18 cans.textAlign = 'left'; 19 cans.textBaseline = 'Middle'; 20 cans.fillText(str,can.width/3,can.height/2); 21 22 body.style.backgroundImage="url("+can.toDataURL("image/png")+")"; 23 24 }