Open thany opened 5 years ago
Having the same problem, plugins are not being invoked, and output file is the same as the input file.
I've tried both of the following and neither is working:
const originalFileBuffer = await readFile(path);
const modifiedFileBuffer = await imagemin.buffer(originalFileBuffer, {
plugins: [
imageminWebp({
quality: 80
})
]
});
await writeFile("uploads/testing.webp", modifiedFileBuffer);
imagemin([path], { destination: 'uploads/' + path.split(uploadDir)[1] + '.webp', plugins: [imageminWebp({ quality: 80 })] }).then((file) => {
console.log('Images optimized');
console.log(file);
cb(null, {
path: path,
filename: path.split(uploadDir)[1],
size: outStream.bytesWritten,
dimensions: dimensions
});
}).catch((err) =>{
console.log(err);
});
In my case it seems that the plugin was unable to support the file type. I'm not sure why no errors were thrown, but I've solved it using different methods and determining the mime type ahead of time....
I've globally installed
imagemin
andimagemin-mozjpeg
. Then, curious how much difference the mozjpeg plugin makes, on a test image I executed:Afterwards, test.min.jpg and test.moz.jpg are byte-for-byte identical. Same size, too. So either the mozjpeg plugin isn't doing anything, or imagemin isn't using it.
I also tried:
Both produce the same result as in the first test. To me it appears the
-p
switch isn't working. I'm also not getting any errors, which is somewhat frusstrating - I have no way of knowing what I'm doing wrong, or if it can't find the plugin (and WHERE it can't find the plugin if that's the case). Maybe the plugin spews out some error that I can't see.I'm on Windows 10, NodeJS 10.13, NPM 6.4.1.