imagemin / imagemin

Minify images seamlessly
MIT License
5.56k stars 258 forks source link

Plugin switch might not be working #327

Open thany opened 5 years ago

thany commented 5 years ago

I've globally installed imagemin and imagemin-mozjpeg. Then, curious how much difference the mozjpeg plugin makes, on a test image I executed:

imagemin test.jpg > test.min.jpeg
imagemin -p=mozjpeg test.jpg > test.moz.jpeg

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:

imagemin -p=imagemin-mozjpeg test.jpg > test.min.jpeg
imagemin -p=yolo test.jpg > test.min.jpeg

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.

mhstoller commented 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);
                    });
mhstoller commented 5 years ago

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....