Skip to content

Instantly share code, notes, and snippets.

@mattparker
Last active August 29, 2015 14:14
Show Gist options
  • Save mattparker/f55aed4103c342ba8b07 to your computer and use it in GitHub Desktop.
Save mattparker/f55aed4103c342ba8b07 to your computer and use it in GitHub Desktop.
Makes an image out of the content of a webpage
javascript:(function () {
var d = document.createElement('canvas'),
ctx = d.getContext('2d'),
w = window.innerWidth,
h = window.innerHeight,
x = 0,
code_to_0256 = function (code) {
if (code < 32 || code > 127) {
code = 90;
}
return Math.floor((code - 32) * (256/95));
},
imageData, imData, text;
d.setAttribute("style", "width: " + w + "px; height: " + h +"px;display: block;");
document.body.insertBefore(d, document.body.firstChild);
imageData = ctx.getImageData(0, 0, w, h);
imData = imageData.data;
text = document.body.textContent;
while (x < imData.length ){
imData[x]= code_to_0256(text.charCodeAt(x % text.length));
x++;
}
ctx.putImageData(imageData, 0, 0);
}());
@mattparker
Copy link
Author

For Twitter

Here's a similar thing that tries to inject the image just below a tweet. Add it as a bookmark, click on a Tweet, and maybe, just maybe, it'll manage to put a little image in the right place.

https://gist.github.com/mattparker/e80b103fe59a9aab7483

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment