Skip to content

Instantly share code, notes, and snippets.

@therealkevinard
Created January 19, 2018 20:59
Show Gist options
  • Save therealkevinard/22585e0cdcdcd81a32396f68a842fe42 to your computer and use it in GitHub Desktop.
Save therealkevinard/22585e0cdcdcd81a32396f68a842fe42 to your computer and use it in GitHub Desktop.
Resize Imgs... the easy way.
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');
}
{
"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