【问题标题】:imagemin - code executes but nothing seems to happensimagemin - 代码执行但似乎没有任何反应
【发布时间】:2021-07-18 13:14:31
【问题描述】:

我正在尝试使用 Typescript 并使用 imagemin 压缩 Node 14 中的图像。

我拿了我在网上找到的例子并运行了代码,但似乎什么也没发生,它完成没有任何错误。 输出也是空的。

imagemin 版本 7.0.1
节点 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));
}

我构建代码然后运行它,但输出只是一个空数组[]。 此外,../compressed-images 文件夹中没有任何内容。

请告诉我如何解决这个问题。

【问题讨论】:

    标签: node.js typescript imagemin


    【解决方案1】:

    问题是由于路径没有作为过时路径传递。这是工作代码:

    const pv = path.join(__dirname, '../../David.jpeg');
    
    const files = await imagemin([pv], {
        destination: path.join(__dirname, '../../compressed-images'),
        plugins: [
            imageminMozjpeg({quality: 50})
        ]
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-16
      • 1970-01-01
      • 2013-02-03
      • 1970-01-01
      • 1970-01-01
      • 2021-10-21
      • 2021-01-03
      • 1970-01-01
      相关资源
      最近更新 更多