Created
August 14, 2015 08:23
-
-
Save shenqihui/04e50f8b3b2396580f01 to your computer and use it in GitHub Desktop.
wm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bin2hex(s) { | |
var i, l, o = '', n; | |
s += ''; | |
for (i = 0, l = s.length; i < l; i++) { | |
n = s.charCodeAt(i).toString(16); | |
o += n.length < 2 ? '0' + n : n; | |
} | |
return o; | |
} | |
var canvas = document.createElement('canvas'); | |
var ctx = canvas.getContext('2d'); | |
var txt = 'http://www.google.com/'; | |
ctx.textBaseline = "top"; | |
ctx.font = "14px 'Arial'"; | |
ctx.textBaseline = "tencent"; | |
ctx.fillStyle = "#f60"; | |
ctx.fillRect(125,1,62,20); | |
ctx.fillStyle = "#069"; | |
ctx.fillText(txt, 2, 15); | |
ctx.fillStyle = "rgba(102, 204, 0, 0.7)"; | |
ctx.fillText(txt, 4, 17); | |
var b64 = canvas.toDataURL().replace("data:image/png;base64,",""); | |
var bin = atob(b64); | |
var crc = bin2hex(bin.slice(-16,-12)); | |
console.log(crc); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment