├── .gitattributes ├── .gitignore ├── vendor ├── osx │ └── pngquant ├── win │ └── pngquant.exe └── linux │ ├── x64 │ └── pngquant │ └── x86 │ └── pngquant ├── test ├── fixtures │ └── test.png └── test.js ├── .travis.yml ├── index.js ├── cli.js ├── .jshintrc ├── .editorconfig ├── lib ├── index.js └── install.js ├── README.md ├── LICENSE.md └── package.json /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | test/tmp 3 | vendor/pngquant* 4 | -------------------------------------------------------------------------------- /vendor/osx/pngquant: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/podio/pngquant-bin/master/vendor/osx/pngquant -------------------------------------------------------------------------------- /test/fixtures/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/podio/pngquant-bin/master/test/fixtures/test.png -------------------------------------------------------------------------------- /vendor/win/pngquant.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/podio/pngquant-bin/master/vendor/win/pngquant.exe -------------------------------------------------------------------------------- /vendor/linux/x64/pngquant: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/podio/pngquant-bin/master/vendor/linux/x64/pngquant -------------------------------------------------------------------------------- /vendor/linux/x86/pngquant: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/podio/pngquant-bin/master/vendor/linux/x86/pngquant -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 'iojs' 4 | - '0.12' 5 | - '0.10' 6 | before_install: 7 | - 'sudo apt-get install -qqy libpng-dev zlib1g-dev' 8 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var bin = require('./lib'); 4 | 5 | /** 6 | * Module exports 7 | */ 8 | 9 | module.exports.path = bin.path(); 10 | module.exports.version = bin.v; 11 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | 4 | var bin = require('./').path; 5 | var input = process.argv.slice(2); 6 | var spawn = require('child_process').spawn; 7 | 8 | spawn(bin, input, { stdio: 'inherit' }) 9 | .on('exit', process.exit); 10 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "bitwise": true, 3 | "camelcase": true, 4 | "curly": true, 5 | "eqeqeq": true, 6 | "esnext": true, 7 | "immed": true, 8 | "newcap": true, 9 | "noarg": true, 10 | "node": true, 11 | "quotmark": "single", 12 | "strict": true, 13 | "undef": true, 14 | "unused": "vars" 15 | } 16 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = tab 6 | indent_size = 4 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.json] 13 | indent_style = space 14 | indent_size = 2 15 | 16 | [*.md] 17 | trim_trailing_whitespace = false 18 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var BinWrapper = require('bin-wrapper'); 4 | var path = require('path'); 5 | var pkg = require('../package.json'); 6 | 7 | /** 8 | * Variables 9 | */ 10 | 11 | var BIN_VERSION = '2.3.4'; 12 | var BASE_URL = 'https://raw.github.com/imagemin/pngquant-bin/v' + pkg.version + '/vendor/'; 13 | 14 | /** 15 | * Initialize a new BinWrapper 16 | */ 17 | 18 | var bin = new BinWrapper({ global: true, progress: false }) 19 | .src(BASE_URL + 'osx/pngquant', 'darwin') 20 | .src(BASE_URL + 'linux/x86/pngquant', 'linux', 'x86') 21 | .src(BASE_URL + 'linux/x64/pngquant', 'linux', 'x64') 22 | .src(BASE_URL + 'win/pngquant.exe', 'win32') 23 | .dest(path.join(__dirname, '../vendor')) 24 | .use(process.platform === 'win32' ? 'pngquant.exe' : 'pngquant'); 25 | 26 | /** 27 | * Module exports 28 | */ 29 | 30 | module.exports = bin; 31 | module.exports.v = BIN_VERSION; 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pngquant-bin [![Build Status](http://img.shields.io/travis/imagemin/pngquant-bin.svg?style=flat)](https://travis-ci.org/imagemin/pngquant-bin) 2 | 3 | > pngquant is a command-line utility for converting 24/32-bit PNG images to paletted (8-bit) PNGs. The conversion reduces file sizes significantly (often as much as 70%) and preserves full alpha transparency. 4 | 5 | 6 | ## Install 7 | 8 | ```sh 9 | $ npm install --save pngquant-bin 10 | ``` 11 | 12 | 13 | ## Usage 14 | 15 | ```js 16 | var execFile = require('child_process').execFile; 17 | var pngquant = require('pngquant-bin').path; 18 | 19 | execFile(pngquant, ['-o', 'output.png', 'input.png'], function (err) { 20 | if (err) { 21 | throw err; 22 | } 23 | 24 | console.log('Image minified!'); 25 | }); 26 | ``` 27 | 28 | 29 | ## CLI 30 | 31 | ```sh 32 | $ npm install --global pngquant-bin 33 | ``` 34 | 35 | ```sh 36 | $ pngquant --help 37 | ``` 38 | 39 | 40 | ## License 41 | 42 | MIT © [imagemin](https://github.com/imagemin) 43 | -------------------------------------------------------------------------------- /lib/install.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var bin = require('./'); 4 | var BinBuild = require('bin-build'); 5 | var log = require('logalot'); 6 | 7 | /** 8 | * Install binary and check whether it works. 9 | * If the test fails, try to build it. 10 | */ 11 | 12 | bin.run(['--version'], function (err) { 13 | if (err) { 14 | log.warn(err.message); 15 | log.warn('pngquant pre-build test failed'); 16 | log.info('compiling from source'); 17 | 18 | var libpng = process.platform === 'darwin' ? 'libpng' : 'libpng-dev'; 19 | var builder = new BinBuild() 20 | .src('https://github.com/pornel/pngquant/archive/' + bin.v + '.tar.gz') 21 | .cmd('make install BINPREFIX="' + bin.dest() + '"'); 22 | 23 | return builder.run(function (err) { 24 | if (err) { 25 | err.message = [ 26 | 'pngquant failed to build, make sure that', 27 | libpng + ' is installed' 28 | ].join(' '); 29 | 30 | log.error(err.stack); 31 | return; 32 | } 33 | 34 | log.success('pngquant built successfully'); 35 | }); 36 | } 37 | 38 | log.success('pngquant pre-build test passed successfully'); 39 | }); 40 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) imagemin 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pngquant-bin", 3 | "version": "2.0.4-podio", 4 | "description": "pngquant wrapper that makes it seamlessly available as a local dependency", 5 | "license": "MIT", 6 | "repository": "imagemin/pngquant-bin", 7 | "author": { 8 | "name": "Kevin Mårtensson", 9 | "email": "kevinmartensson@gmail.com", 10 | "url": "http://kevinmartensson.com" 11 | }, 12 | "engines": { 13 | "node": ">=0.10.0" 14 | }, 15 | "bin": { 16 | "pngquant": "cli.js" 17 | }, 18 | "scripts": { 19 | "postinstall": "node lib/install.js", 20 | "test": "mkdir test/tmp && node test/test.js && rm -rf test/tmp" 21 | }, 22 | "files": [ 23 | "cli.js", 24 | "index.js", 25 | "lib" 26 | ], 27 | "keywords": [ 28 | "compress", 29 | "image", 30 | "img", 31 | "minify", 32 | "optimize", 33 | "png" 34 | ], 35 | "dependencies": { 36 | "bin-build": "^2.0.0", 37 | "bin-wrapper": "^3.0.0", 38 | "logalot": "^2.0.0" 39 | }, 40 | "devDependencies": { 41 | "ava": "^0.0.4", 42 | "bin-check": "^1.0.0", 43 | "compare-size": "^1.0.0" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var binCheck = require('bin-check'); 4 | var BinBuild = require('bin-build'); 5 | var compareSize = require('compare-size'); 6 | var execFile = require('child_process').execFile; 7 | var fs = require('fs'); 8 | var path = require('path'); 9 | var test = require('ava'); 10 | var tmp = path.join(__dirname, 'tmp'); 11 | 12 | test('rebuild the pngquant binaries', function (t) { 13 | t.plan(2); 14 | 15 | var version = require('../').version; 16 | var builder = new BinBuild() 17 | .src('https://github.com/pornel/pngquant/archive/' + version + '.tar.gz') 18 | .cmd('make install BINPREFIX="' + tmp + '"'); 19 | 20 | builder.run(function (err) { 21 | t.assert(!err, err); 22 | 23 | fs.exists(path.join(tmp, 'pngquant'), function (exists) { 24 | t.assert(exists); 25 | }); 26 | }); 27 | }); 28 | 29 | test('return path to binary and verify that it is working', function (t) { 30 | t.plan(2); 31 | 32 | binCheck(require('../').path, ['--version'], function (err, works) { 33 | t.assert(!err, err); 34 | t.assert(works); 35 | }); 36 | }); 37 | 38 | test('minify a PNG', function (t) { 39 | t.plan(3); 40 | 41 | var src = path.join(__dirname, 'fixtures/test.png'); 42 | var dest = path.join(tmp, 'test.png'); 43 | var args = [ 44 | '-o', dest, 45 | src 46 | ]; 47 | 48 | execFile(require('../').path, args, function (err) { 49 | t.assert(!err, err); 50 | 51 | compareSize(src, dest, function (err, res) { 52 | t.assert(!err, err); 53 | t.assert(res[dest] < res[src]); 54 | }); 55 | }); 56 | }); 57 | --------------------------------------------------------------------------------