imagemin-webp
imagemin-webp copied to clipboard
Console shows "Images Optimized", but there are no images in output folder.
Hi, in "images/" I have several .jpg images. I use the code from example and run it in node.js environment. After running the script I'm getting 'Images optimized' in console log, but nothing happens. The whole process takes less than 1 sec. Are those images converted, but not saved? Or they're just skipped?
yes thats true, me too.
Yes, the problem does not seem to be with the plugin itself, however. It looks like a possible upstream issue: https://github.com/imagemin/imagemin/issues/327
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....
Ultimately the plugin is using this library: https://www.npmjs.com/package/cwebp-bin
So it seems if the image conversion fails in that library then the output from imagemin is the original file.
Also example of usage on imagemin-webp is little bit misleading, dunno if imagemin has a new API but below should work:
const imagemin = require('imagemin');
const imageminWebp = require('imagemin-webp');
(async () => {
const files = await imagemin(['./images/*.{jpg}'], {
destination: 'build/images',
plugins: [imageminWebp()],
});
console.log(files);
})();
Had the same problem and @cksho example code solved it.
Hello, I already used the destination
key in the options object, but that only makes a copy of the original jpg
file I try to convert to webp
. It doesn't create a new image with webp
extension.
const imagemin = require('imagemin');
const imageminWebp = require('imagemin-webp');
(async () => {
const img = await imagemin(['images/*.jpg'], {
destination: 'build/images',
use: [
imageminWebp({quality: 100})
]
});
console.log('Images optimized');
console.log(img)
})();
For those who are having this problem, the use
keyword is no longer working. plugins
is the correct option.
const imagemin = require('imagemin');
const imageminWebp = require('imagemin-webp');
(async () => {
const img = await imagemin(['images/*.jpg'], {
destination: 'build/images',
plugins: [
imageminWebp({quality: 100})
]
});
console.log('Images optimized');
console.log(img)
})();
For Windows users. You need to replace slahes to unix format
const path = require('path');
const imagemin = require('imagemin');
const imageminWebp = require('imagemin-webp');
(async () => {
const img = await imagemin([path.resolve(__dirname, 'img/*.{jpg,png}').replace(/\\/g, '/')], {
destination: path.resolve(__dirname, 'dist/webp').replace(/\\/g, '/'),
plugins: [imageminWebp({ quality: 70 })],
});
console.log('Images optimized');
console.log(img);
})();
it can’t done, and the problem still as usuall @LambdaZed
Hi! Did someone find a solution? It is still a problem...