Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First commit

  • Loading branch information...
commit 33aba36c5927020c08990dbcd201afcfa251163d 0 parents
@chriso chriso authored
Showing with 161 additions and 0 deletions.
  1. +20 −0 LICENSE
  2. +58 −0 README.md
  3. +68 −0 index.js
  4. +15 −0 package.json
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2012 Sydney Stockholm <opensource@sydneystockholm.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
58 README.md
@@ -0,0 +1,58 @@
+**jpegmini** - a wrapper for the [jpegmini](http://www.jpegmini.com) command line tool
+
+## Installation
+
+```bash
+$ npm install jpegmini
+```
+
+## Usage
+
+Compress an image
+
+```javascript
+var jpegmini = require('jpegmini');
+
+jpegmini.process({
+ input: '/path/to/input.jpg'
+ , output: '/path/to/output.jpg'
+ , quality: jpegmini.BEST
+ , skip_compressed: true
+ , remove_metadata: false
+ , license_cache: '/etc/jpegmini_cache'
+}, function (err) {
+ //..
+});
+```
+
+Logging out the cached license
+
+```javascript
+jpegmini.logout('/path/to/license_cache', function (err) {
+ //...
+});
+```
+
+## License (MIT)
+
+Copyright (c) 2012 Sydney Stockholm <opensource@sydneystockholm.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
68 index.js
@@ -0,0 +1,68 @@
+var exec = require('child_process').exec;
+
+exports.MEDIUM = 2;
+exports.HIGH = 1;
+exports.BEST = 0;
+
+function jpegmini(options, callback) {
+ var args = Object.keys(options).map(function (key) {
+ var value = options[key];
+ if (typeof value === 'number') {
+ value += '';
+ } else if (typeof value === 'string') {
+ value = '"' + value.replace(/"/g, '\\"') + '"';
+ }
+ return '-' + key + '=' + value.replace(/`/g, '');
+ }).join(' ');
+ exec('jpegmini ' + args, callback);
+}
+
+exports.process = function (options, callback) {
+ var cli = {};
+ if (options.input) {
+ cli.f = options.input;
+ }
+ if (options.output) {
+ cli.o = options.output;
+ }
+ if (options.recurse !== false) {
+ cli.r = 1;
+ } else {
+ cli.r = 0;
+ }
+ if (options.license_cache) {
+ cli.lc = options.license_cache;
+ }
+ if (options.resize) {
+ cli.rsz = options.resize;
+ }
+ switch (options.quality) {
+ case exports.MEDIUM:
+ cli.qual = 2;
+ break;
+ case exports.HIGH:
+ cli.qual = 1;
+ break;
+ default:
+ cli.qual = 0;
+ break;
+ }
+ if (options.skip_compressed) {
+ cli.shc = 1;
+ }
+ if (options.remove_metadata) {
+ cli.rmt = 1;
+ }
+ jpegmini(cli, callback);
+};
+
+exports.logout = function (cache, callback) {
+ //Jpegmini requires a -f option, even if we just want to logout the license
+ jpegmini({ lc_logout: cache, f: '/tmp/_.jpg' }, function (err) {
+ if (err.message.indexOf('7032') !== -1) {
+ err = null;
+ }
+ callback(err);
+ });
+};
+
15 package.json
@@ -0,0 +1,15 @@
+{
+ "name": "jpegmini",
+ "version": "0.1.0",
+ "description": "A wrapper for the command line tool jpegmini",
+ "main": "index.js",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/sydneystockholm/jpegmini"
+ },
+ "keywords": [
+ "jpegmini"
+ ],
+ "author": "Sydney Stockholm <opensource@sydneystockholm.com>",
+ "license": "MIT"
+}
Please sign in to comment.
Something went wrong with that request. Please try again.