Skip to content

Instantly share code, notes, and snippets.

@mattparker
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattparker/e80b103fe59a9aab7483 to your computer and use it in GitHub Desktop.
Save mattparker/e80b103fe59a9aab7483 to your computer and use it in GitHub Desktop.
picture your tweet
javascript:(function () {
var d = document.createElement('canvas'),
ctx = d.getContext('2d'),
tweet = document.querySelector('.expanded-conversation .tweet .tweet-text'),
box,
w,
h = 80,
x = 0,
code_to_0256 = function (code) {
if (code < 32 || code > 127) {
code = 90;
}
return Math.floor((code - 32) * (256/95));
},
imageData, imData,
text;
if (!tweet) {
return;
}
box = tweet.getBoundingClientRect();
w = box.width;
text = tweet.textContent;
d.setAttribute("style", "width: " + w + "px; height: " + h +"px;display: block;");
tweet.appendChild(d);
imageData = ctx.getImageData(0, 0, w, h);
imData = imageData.data;
while (x < imData.length ){
imData[x]= code_to_0256(text.charCodeAt(x % text.length));
x++;
}
ctx.putImageData(imageData, 0, 0);
}());
@mattparker
Copy link
Author

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