PNG scaling for Node.js depending only on pngjs.
npm install png-scalebash
npm install png-scale
`
Usage
$3
This a complete example. Just set your filename: in_fn.
`js
const PNGScale = require('png-scale');
const fs = require('fs');
var in_fn = "input.png";
var out_fn = "output.png";
var config = {dst:{width:"30%",height:"30%"}};
var in_file = fs.createReadStream(in_fn)
.on('error',function(e) {console.log("Error reading file.",e); });
var out_file = fs.createWriteStream(out_fn)
.on('error',function(e) {console.log("Error writing file.",e); })
.on('close',function() {
console.log("Scaling complete!");
console.log(" input:",in_fn);
console.log(" output:",out_fn);
console.log(" config:",JSON.stringify(config));
});
PNGScale.scale(in_file,config,function(err,data) {
if(err) { console.log("Error with scaling.",err); }
else { data.pipe(out_file); }
});
`
$3
Same as above with single line changed.
`js
var config = {dst:{width:"200px",height:"100px"}};
`
'px' is optional. This is the same as above.
`js
var config = {dst:{width:"200",height:"100"}};
`
$3
Scale proportionally by percentage.
`js
var config = {dst:{width:"30%"}};
`
Scale proportionally to size.
`js
var config = {dst:{height:"100px"}};
`
$3
Scale proportionally and output as colorType:0 (grayscale).
`js
var config = {dst:{width:"50%"},PNG:{colorType:0}};
``