0

I'm trying to compress an image in Node 14 with Typescript and using imagemin.

I took the examples I found online and run the code, but nothing seems to happen, it finishes without any errors. The output is empty as well.

imagemin version 7.0.1
node v14.15.4

'use strict';
import imagemin from 'imagemin';
import imageminJpegtran from 'imagemin-jpegtran';

export async function compressImage(): Promise<void> {

const files = await imagemin(['../David.jpeg'], {
    destination: '../compressed-images',
    plugins: [
        imageminJpegtran(),
    ]
});

console.log(JSON.stringify(files, null, 1));
}

I build the code and then run it but the output is simply an empty array []. Also, nothing appears in the ../compressed-images folder.

Please advise on how I can resolve this.

David Faizulaev
  • 4,651
  • 21
  • 74
  • 124

1 Answers1

0

Issue was due to the path no being passed as obsolete path. This is the working code:

const pv = path.join(__dirname, '../../David.jpeg');

const files = await imagemin([pv], {
    destination: path.join(__dirname, '../../compressed-images'),
    plugins: [
        imageminMozjpeg({quality: 50})
    ]
});
David Faizulaev
  • 4,651
  • 21
  • 74
  • 124