Created
December 24, 2021 12:49
-
-
Save vojtaholik/1d37868f34c7686e4062a49c21a18dbb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Menu: Compress Images | |
// Description: Compress images using imagemin | |
// Author: Vojta Holik | |
// Twitter: @vjthlk | |
/** @type {import("@johnlindquist/kit")} */ | |
let imagemin = await npm("imagemin"); | |
let imageminJpegtran = await npm("imagemin-jpegtran"); | |
let imageminJpegRecompress = await npm("imagemin-jpeg-recompress"); | |
let imageminPngquant = await npm("imagemin-pngquant"); | |
let imageminSvgo = await npm("imagemin-svgo"); | |
let imageminGifsicle = await npm("imagemin-gifsicle"); | |
let selectedFiles = await getSelectedFile(); | |
let filePaths; | |
if (selectedFiles) { | |
filePaths = selectedFiles.split("\n"); | |
} else { | |
let droppedFiles = await drop({ placeholder: "Drop images to compress" }); | |
filePaths = droppedFiles.map((file) => file.path); | |
} | |
for (let filePath of filePaths) { | |
let directory = path.dirname(filePath); | |
await imagemin([filePath], { | |
destination: directory, | |
plugins: [ | |
imageminJpegtran({ | |
arithmetic: true, | |
progressive: true, | |
}), | |
imageminJpegRecompress({ max: 85 }), | |
imageminSvgo(), | |
imageminGifsicle({ | |
optimizationLevel: 2, | |
}), | |
imageminPngquant({ | |
quality: [0.3, 0.5], | |
}), | |
], | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment