Skip to content
This repository has been archived by the owner on Apr 2, 2023. It is now read-only.

mikehall314/teenypng

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

teenypng

Optimize PNG + JPEG images with TinyPNG.

Command Line

Install with NPM.

$ npm install -g teenypng
$ teenypng images/*.png --apikey XXXXXXXXXX

As a module

Install

$ npm install --save-dev teenypng

Use

"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>
    //     }
    // }
});

Settings

  • 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"
    //     }
    // }
});

Tests

Test with nodeunit

$ npm test