imagemin-sharp
Imagemin plugin for sharp
Installation
npm install imagemin-sharp --save
Usage
import imagemin from "imagemin";
import imageminSharp from "imagemin-sharp";
const files = await imagemin(["images/*.{jpg,png}"], {
destination: "build/images",
plugins: [
imageminSharp({
chainSharp: async (sharp) => {
const meta = await sharp.metadata();
if (meta.width > 1000) {
return sharp.flip().resize({ width: 1000 });
}
return sharp.flip();
},
}),
],
});
console.log(files);
Options
Options is a union of chainSharp
and SharpOptions
-
chainSharp
: A callback to chain operate sharp instance, returnSharp | Promise<Sharp>
-
SharpOptions
: Sharp constructor options, can referrer https://sharp.pixelplumbing.com/api-constructor