Created
January 19, 2018 20:59
-
-
Save therealkevinard/22585e0cdcdcd81a32396f68a842fe42 to your computer and use it in GitHub Desktop.
Resize Imgs... the easy way.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const imagemin = require('imagemin'); | |
const ImageminGm = require('imagemin-gm'); | |
const Imagemin_jpgMoz = require('imagemin-mozjpeg'); | |
const imagemin_gm = new ImageminGm(); | |
const imPlugins = [ | |
imagemin_gm.resize({ | |
width: 700, | |
gravity: 'Center' | |
}), | |
Imagemin_jpgMoz({ | |
quality: 100, | |
}), | |
]; | |
optimize() | |
.then(res => { | |
console.log(res) | |
}) | |
.catch(err => { | |
console.error(err) | |
}); | |
async function optimize() { | |
await imagemin( | |
['src/*.jpg', 'src/*.png'], | |
'build/images', | |
{ | |
plugins: imPlugins | |
} | |
); | |
console.log('done'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "process-images", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"imagemin": "^5.3.1", | |
"imagemin-gm": "^2.0.0", | |
"imagemin-jpegtran": "^5.0.2", | |
"imagemin-mozjpeg": "^7.0.0", | |
"mozjpeg": "^5.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment