将 JS 代码放入图片文件
void function(){
var source = 'js.png'; // 存放JS代码的图片
var img = document.createElement('img');
img.src = source;
img.onload = function(){
var canvas = document.createElement('canvas');
canvas.width = img.width;
canvas.height = img.height;
var context = canvas.getContext("2d");
context.drawImage(img, 0, 0);
var imageData = context.getImageData(0, 0, canvas.width, canvas.height),
pixels = imageData.data;
var buffer = [];
for (var i = 0, l = pixels.length; i < l; i++) {
if (i % 4 == 3) continue; // 第4个是透明度,不能存值(这一位的值最大是100、ASCII码会超过100)
if (!pixels[i]) break;
buffer.push(String.fromCharCode(pixels[i]));
}
document.write('<pre>'+buffer.join('')+'</pre>');
img = null;
}
}();