Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created April 19, 2012 15:32
Show Gist options
  • Save tmcw/2421754 to your computer and use it in GitHub Desktop.
Save tmcw/2421754 to your computer and use it in GitHub Desktop.
var Canvas = require('canvas'),
Image = Canvas.Image,
fs = require('fs');
var w = 612;
var c = new Canvas(w, w);
var ctx = c.getContext('2d');
ctx.fillStyle = '#fff';
ctx.fillRect(0, 0, w, w);
var input = process.argv.slice(2);
var datas = input.map(function(i) {
var img = new Image();
img.src = fs.readFileSync(i);
var ct = new Canvas(w, w);
var ctxt = ct.getContext('2d');
ctxt.drawImage(img, 0, 0, w, w);
return ctxt.getImageData(0, 0, w, w);
});
function getpx(data, x, y) {
var r = data[4 * ((y * w) + x) + 0],
g = data[4 * ((y * w) + x) + 1],
b = data[4 * ((y * w) + x) + 2];
return [r, g, b];
}
for (var x = 0; x < 640; x += 1) {
for (var y = 0; y < w; y += 1) {
var px = getpx(datas[(Math.floor(x / 5) * 5) % datas.length].data, Math.round(x * (612 / 640)), y);
ctx.fillStyle = 'rgb(' + px.join(',') + ')';
ctx.fillRect(x, y, 1, 1);
}
}
fs.writeFileSync('out_horiz.png', c.toBuffer());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment