mirror of
https://github.com/danbulant/pngjs
synced 2026-06-19 22:41:58 +00:00
expand example to create a new file
This commit is contained in:
parent
912df207b5
commit
45033d4031
1 changed files with 19 additions and 6 deletions
|
|
@ -1,10 +1,23 @@
|
|||
var PNG = require("../lib/png").PNG;
|
||||
|
||||
(new PNG({width:1,height:1})).pack()
|
||||
.on('data', function(data) {
|
||||
console.log('data', data);
|
||||
})
|
||||
.on('end', function() {
|
||||
var newfile = new PNG({width:10,height:10});
|
||||
|
||||
for (var y = 0; y < png.height; y++) {
|
||||
for (var x = 0; x < png.width; x++) {
|
||||
var idx = (png.width * y + x) << 2;
|
||||
|
||||
var col = x < (png.width >> 1) ^ y < (png.height >> 1) ? 0xe5 : 0xff;
|
||||
|
||||
png.data[idx] = col;
|
||||
png.data[idx + 1] = col;
|
||||
png.data[idx + 2] = col;
|
||||
png.data[idx + 3] = 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
newfile.pack()
|
||||
.pipe(fs.createWriteStream(__dirname + '/newfile.png'))
|
||||
.on('finish', function() {
|
||||
console.log('bitmap:', this.data);
|
||||
console.log('end !');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue