imagemin-webp icon indicating copy to clipboard operation
imagemin-webp copied to clipboard

Console shows "Images Optimized", but there are no images in output folder.

Open nordskill opened this issue 5 years ago • 10 comments

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?

nordskill avatar Jul 24 '19 11:07 nordskill

yes thats true, me too.

BoniWPy avatar Aug 08 '19 09:08 BoniWPy

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

mhstoller avatar Aug 18 '19 14:08 mhstoller

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.

mhstoller avatar Aug 18 '19 14:08 mhstoller

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);
})();

cksho avatar Aug 24 '19 13:08 cksho

Had the same problem and @cksho example code solved it.

oproulx avatar Oct 27 '19 16:10 oproulx

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)
})();

4k1k0 avatar Jan 02 '20 19:01 4k1k0

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)
})();

AskingQuestions avatar May 26 '20 15:05 AskingQuestions

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);
})();

LambdaZed avatar Feb 19 '21 15:02 LambdaZed

it can’t done, and the problem still as usuall @LambdaZed

qwekelly avatar Mar 13 '21 08:03 qwekelly

Hi! Did someone find a solution? It is still a problem...

PyGod avatar Apr 16 '24 06:04 PyGod