0

我正在尝试为经过处理的图像指定一个输出目录eleventy-img

const Image = require("@11ty/eleventy-img");

(async () => {
  let url = "./img/home/";

  let stats = await Image(url, {
    widths: [300],
    outputDir: "./img/processed/",
  });

  console.log(stats);
})();

但是当我运行时我得到的是这个错误消息npx eleventy

Unhandled rejection in promise ([object Promise]): (more in DEBUG output)
> Input file contains unsupported image format

`Error` was thrown:
    Error: Input file contains unsupported image format

如果没有outputDir指定选项,它可以正常工作。这是它的文档:https ://www.11ty.dev/docs/plugins/image/#output-directory

没有使用它的实际示例,但从逻辑上讲,它应该以与widths参数相同的方式传递。

4

1 回答 1

0

我发现了我的错误。我试图通过"./img/home/". 相反,我需要传递单个图像,然后它才能工作。

像这样:

const Image = require("@11ty/eleventy-img");

(async () => {
  let url = "./img/home/my-image.jpg";

  let stats = await Image(url, {
    widths: [300],
    outputDir: "./img/processed",
  });

  console.log(stats);
})();
于 2021-04-26T14:28:07.087 回答