Skip to content

Instantly share code, notes, and snippets.

@panreel
Created March 11, 2018 16:07
Show Gist options
  • Save panreel/1e31ac57b8f14283b63f79cd61a11eff to your computer and use it in GitHub Desktop.
Save panreel/1e31ac57b8f14283b63f79cd61a11eff to your computer and use it in GitHub Desktop.
NPM Img Compression Script
const dir = require('node-dir');
var jimp = require("jimp");
const args = process.argv;
dir.promiseFiles(args[2])
.then(files => {
for(let file of files) {
jimp.read(file).then(image => {
image
.quality(60)
.resize(Math.min(800, image.bitmap.width), jimp.AUTO)
.write(args[3] + file + '.' + image.getExtension());
})
}
})
.catch(error => console.log(error));
{
"name": "npm-minify",
"version": "1.0.0",
"description": "## Your Goals: ##",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"compress": "node compress.js %npm_package_config_src% %npm_package_config_out%"
},
"devDependencies": {
"jimp": "^0.2.28",
"node-dir": "^0.1.17"
},
"config": {
"src": "./images_src",
"out": "./dest/"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment