mirror of
https://github.com/danbulant/pngjs
synced 2026-05-27 05:41:47 +00:00
25 lines
760 B
JavaScript
25 lines
760 B
JavaScript
|
|
var fs = require('fs'),
|
|
PNG = require('../lib/png').PNG; // note require('pngjs') outside this project
|
|
|
|
fs.createReadStream('test/in/basi0g01.png')
|
|
.pipe(new PNG({
|
|
}))
|
|
.on('parsed', function() {
|
|
|
|
for (var y = 0; y < this.height; y++) {
|
|
for (var x = 0; x < this.width; x++) {
|
|
var idx = (this.width * y + x) << 2;
|
|
|
|
// invert color
|
|
this.data[idx] = 255 - this.data[idx];
|
|
this.data[idx+1] = 255 - this.data[idx+1];
|
|
this.data[idx+2] = 255 - this.data[idx+2];
|
|
|
|
// and reduce opacity
|
|
this.data[idx+3] = this.data[idx+3] >> 1;
|
|
}
|
|
}
|
|
|
|
this.pack().pipe(fs.createWriteStream('out.png'));
|
|
});
|