mirror of
https://github.com/danbulant/pngjs
synced 2026-07-08 04:30:33 +00:00
Fix newfile example. Fixes #35
This commit is contained in:
parent
5ee7782212
commit
1ba93c2af8
1 changed files with 10 additions and 10 deletions
|
|
@ -1,23 +1,23 @@
|
||||||
var PNG = require("../lib/png").PNG;
|
var PNG = require("../lib/png").PNG;
|
||||||
|
var fs = require("fs");
|
||||||
|
|
||||||
var newfile = new PNG({width:10,height:10});
|
var newfile = new PNG({width:10,height:10});
|
||||||
|
|
||||||
for (var y = 0; y < png.height; y++) {
|
for (var y = 0; y < newfile.height; y++) {
|
||||||
for (var x = 0; x < png.width; x++) {
|
for (var x = 0; x < newfile.width; x++) {
|
||||||
var idx = (png.width * y + x) << 2;
|
var idx = (newfile.width * y + x) << 2;
|
||||||
|
|
||||||
var col = x < (png.width >> 1) ^ y < (png.height >> 1) ? 0xe5 : 0xff;
|
var col = x < (newfile.width >> 1) ^ y < (newfile.height >> 1) ? 0xe5 : 0xff;
|
||||||
|
|
||||||
png.data[idx] = col;
|
newfile.data[idx] = col;
|
||||||
png.data[idx + 1] = col;
|
newfile.data[idx + 1] = col;
|
||||||
png.data[idx + 2] = col;
|
newfile.data[idx + 2] = col;
|
||||||
png.data[idx + 3] = 0xff;
|
newfile.data[idx + 3] = 0xff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newfile.pack()
|
newfile.pack()
|
||||||
.pipe(fs.createWriteStream(__dirname + '/newfile.png'))
|
.pipe(fs.createWriteStream(__dirname + '/newfile.png'))
|
||||||
.on('finish', function() {
|
.on('finish', function() {
|
||||||
console.log('bitmap:', this.data);
|
console.log('Written!');
|
||||||
console.log('end !');
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue