如何在@11ty/eleventy-img 中为我处理的图像指定 outputDir?

问题描述

我正在尝试为经过 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 选项的情况下工作正常。 这是它的文档:this

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

解决方法

我发现了我的错误。我试图用 "./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);
})();

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...