Created
April 16, 2015 18:17
-
-
Save mickm/4161975cfe98d8d30179 to your computer and use it in GitHub Desktop.
rgba -> png example
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
#!/usr/bin/env node | |
var Png = require('png').Png; // https://github.com/pkrumins/node-png | |
var fs = require('fs'); | |
var size = 256; | |
var rgba = new Buffer(size*size*4); | |
var x, y; | |
var png; | |
for (y = 0; y < size; y++) { | |
for (x = 0; x < size; x++) { | |
rgba.writeUInt8(y&x, (y*size+x)*4 + 0); | |
rgba.writeUInt8(y&x, (y*size+x)*4 + 1); | |
rgba.writeUInt8(y&x, (y*size+x)*4 + 2); | |
rgba.writeUInt8(y&x, (y*size+x)*4 + 3); | |
} | |
} | |
png = new Png(rgba, size, size, 'rgba'); | |
png.encode(function(data,err) { | |
if (err) { | |
console.error(err); | |
process.exit(1); | |
} | |
fs.writeFileSync('wat.png', data.toString('binary'), 'binary'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment