Optimize PNG + JPEG images with TinyPNG.
Install with NPM.
$ npm install -g teenypng
$ teenypng images/*.png --apikey XXXXXXXXXX
$ npm install --save-dev teenypng
"use strict";
var teenypng = require("teenypng");
teenypng("image.png", { "apikey": "XXXXXXXXXX" }, function (err, optimized) {
// optimized = {
// "input": {
// "size": 207565,
// "name": "image.png"
// },
// "output": {
// "size": 63669,
// "ratio": 0.307,
// "image": <Buffer with compressed image>
// }
// }
});
apikey
: Your API key from tinypng.com (required)onlyStats
: Do not download the optimized file (optional, default: false)
"use strict";
var teenypng, settings;
teenypng = require("teenypng");
settings = {
"apikey": "XXXXXXXXXX",
"onlyStats": true
};
teenypng("image.png", settings, function (err, optimized) {
// optimized = {
// "input": {
// "size": 207565,
// "name": "image.png"
// },
// "output": {
// "size": 63669,
// "ratio": 0.307,
// "url": "https://path.to.optimized/image.png"
// }
// }
});
Test with nodeunit
$ npm test