Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getJpegPlugins(quality) {
// If quality is between 0 - 100 use mozjpeg plugin
if (/^([0-9][0-9]?|100)$/.test(quality)) {
return [
imageminMozjpeg({
quality: quality
})
];
}
if (quality === "perfect") {
return [imageminJpegtran()];
}
if (quality === "ultra") {
return [
imageminJpegRecompress({
min: 10,
max: 95,
target: 0.999901
})
function images () {
return gulp.src(PATHS.images)
.pipe(gulpif(PRODUCTION,
imagemin([
imageminGifsicle({ interlaced: true, optimizationLevel: 3 }),
imageminMozjpeg({ quality: 80 }),
imageminPngquant({ quality: [0.5, 0.8] }),
imagemin.svgo({ plugins: [{ removeViewBox: true }, { cleanupIDs: false }] })
])))
.pipe(gulp.dest(`${PATHS.dist}/assets`))
}
.pipe(gulpIf(isDevelopment, newer(paths.build.imgDir)))
.pipe(
gulpIf(
isProduction && IMAGE_ENCODER_GUETZLI,
imagemin([
guetzli({
quality: IMAGE_COMPRESSION_RATE,
}),
]),
),
)
.pipe(
gulpIf(
isProduction && !IMAGE_ENCODER_GUETZLI,
imagemin([
mozjpeg({
quality: IMAGE_COMPRESSION_RATE,
}),
]),
),
)
.pipe(gulpIf(isProduction, rev()))
.pipe(printFileName("CopyImages"))
.pipe(gulp.dest(paths.build.imgDir))
.pipe(
gulpIf(
isProduction,
combine(
rev.manifest("rev-images.json"),
gulp.dest(paths.build.manifestDir),
),
),
export function imagesOptimize() {
return gulp
.src([`${configs.paths.src}/img/**/*`, `!${configs.paths.src}/img/{icons,icons/**}`])
.pipe(newer('.cache/img'))
.pipe(
imagemin([
imagemin.gifsicle({ interlaced: true }),
imageminMozjpeg({ progressive: true }),
imageminPngquant({
quality: [0.6, 0.8],
}),
imagemin.svgo({ plugins: [{ removeDimensions: true }] }),
]),
)
.pipe(gulp.dest('.cache/img'))
.on('error', notifierErrorHandler);
}
export function images () {
return gulp.src(paths.images.src)
.pipe(plumber(config.plumberConfig))
.pipe(imagemin([
pngquant(),
mozjpeg()
], {
verbose: true
}))
.pipe(gulp.dest(paths.images.dest))
}
const engineJpg = algorithm => {
switch (algorithm) {
case 'jpegoptim':
return imageminJpegoptim({
progressive: false,
});
case 'jpegtran':
return imageminJpegtran({
progressive: true,
});
case 'mozjpeg':
return imageminMozjpeg({
quality: 90,
});
default:
return null;
}
};
processing = {
webp: {
quality: 100
},
jpg: {
quality: 100
},
png: {}
};
optimization = {
webp: webpPlugin({
quality: 100
}),
jpg: mozJpegPlugin({
quality: 100
}),
png: zopfliPlugin(),
gif: gifLossyPlugin(),
svg: svgoPlugin()
};
postfix = (width, mul) => (mul === 1 ? '' : `@${width}w`);
skipOptimization = false;
constructor(config = {}) {
if (typeof config == 'object') {
const { processing, optimization, postfix, skipOptimization } = config;