在Node / Express中工作时,我想获取npm包color-thief来从图像中获取主色,但是失败了,因为“给定的图像尚未完成加载”。
图像还是本地的,因此它不应该有这个特殊的问题。除此之外,还color-thief
返回一个Promise,并且我正在使用async / await,因此它应该等待加载图像所需的时间,而不是抛出错误。
以下是我的SSCCE代码:
const ColorThief = require('color-thief');
let colorThief = new ColorThief();
async function getDominantColor() {
const img = 'public/img/seed/big-waves-2193828__340.webp';
const dominantColor = await colorThief.getColor(img);
console.log(dominantColor);
}
getDominantColor();