'use strict';
const request = require('request');
const fs = require('fs');
const PNG = require('pngjs').PNG;
const MY_COLOR = [0, 128, 255];
request('https://hsto.org/webt/5c/18/70/5c1870eb0ca6c415076037.png')
.pipe(new PNG({
filterType: 4
}))
.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;
this.data[idx + 0] = MY_COLOR[0];
this.data[idx + 1] = MY_COLOR[1];
this.data[idx + 2] = MY_COLOR[2];
this.data[idx + 3] = this.data[idx + 3];
}
}
this.pack().pipe(fs.createWriteStream('result.png'));
});