Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function compressJPEG(filePath) {
const fileDirectory = filePath.substring(0, filePath.lastIndexOf('/'));
return imagemin([filePath], fileDirectory, {
plugins: [
imageminJpegRecompress(true), // Favor accuracy over speed
],
});
}
_compressImage = algorithm => {
const plugin = getPlugin(this.file.type, algorithm);
return imagemin(this.file.path, this.dir, {
plugins: [plugin],
})
.then(file => {
if (file) {
return fs.statSync(file.path).size;
}
throw new Error(`Invalid file name "${this.file.path}".`);
})
.catch(ex => {
console.warn(ex);
let { message } = ex;
if (algorithm === 'jpegoptim' && isLibjpegNotFound(ex)) {
message = 'You probably need to install "libjpeg" on your computer.';
}
this.errors.push({
algorithm,
import Imagemin from "imagemin"
import { join } from "path"
const distDir = join(__dirname, "../dist/")
new Imagemin()
.src(distDir + "**/*.{gif,jpg,png}")
.dest(distDir)
.use(Imagemin.jpegtran({ progressive: true }))
.use(Imagemin.optipng({ optimizationLevel: 3 }))
.use(Imagemin.gifsicle({ interlaced: true }))
.run((err, files) => {
console.log("Optimized files: " + files.length)
if (err) {
console.error(err)
}
})
filePaths.forEach(filePath => {
imagemin([`${filePath}*.png`], path.dirname(`${filePath}*.png`), options).then(files => {
console.log(`${filePath}*.png was optimized, ${files.length} files`);
});
});
return new Promise((accept, reject) => {
let func
if (path.extname(image) == '.jpg' || path.extname(image) == '.jpeg') {
func = Imagemin.jpegtran({progressive: true})
} else if (path.extname(image) == '.png') {
func = Imagemin.optipng({optimizationLevel: 3})
} else if (path.extname(image) == '.gif') {
func = Imagemin.gifsicle({interlaced: true})
}
new Imagemin()
.src(`../../components/Work/Repo/img/${image}`)
.dest('../../components/Work/Repo/img/')
.use(func)
.run(function (err, files) {
return accept(files)
})
})
}
const assets = paths.map(async assetPath => {
const asset = await imagemin([assetPath], '', {
plugins: [
imageminPngquant(options.png),
imageminJpegtran(options.jpg),
imageminGifsicle(options.gif),
imageminSvgo(options.svg)
]
});
asset[0].path = assetPath;
return asset[0];
});