How to use the imagemin function in imagemin

To help you get started, we’ve selected a few imagemin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thegazelle-ad / gazelle-server / src / lib / server-utilities.js View on Github external
export function compressJPEG(filePath) {
  const fileDirectory = filePath.substring(0, filePath.lastIndexOf('/'));
  return imagemin([filePath], fileDirectory, {
    plugins: [
      imageminJpegRecompress(true), // Favor accuracy over speed
    ],
  });
}
github douglasjunior / emage / app / utils / Process.js View on Github external
_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,
github thangngoc89 / blog / old / scripts / imagemin.js View on Github external
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)
    }
  })
github opencollective / opencollective-frontend / scripts / optimize-png.js View on Github external
filePaths.forEach(filePath => {
  imagemin([`${filePath}*.png`], path.dirname(`${filePath}*.png`), options).then(files => {
    console.log(`${filePath}*.png was optimized, ${files.length} files`);
  });
});
github alex-cory / portfolio / src / apis / github / index.js View on Github external
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)
			})
	})
}
github DanWebb / jdown / src / transform-assets.ts View on Github external
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];
  });

imagemin

Minify images seamlessly

MIT
Latest version published 3 years ago

Package Health Score

79 / 100
Full package analysis