node.js - ColorThief.getColor() TypeError: url.indexOf 不是函数
问题描述
我正在尝试在 node.js 环境中使用 ColorThief。调用 ColorThief.getColor() 时出现以下错误:
TypeError:url.indexOf 不是函数
错误来自模块中的这行代码。
if(url.indexOf('data:image/gif;')
这是我的代码:
const ColorThief = require('colorthief');
const img = document.querySelector('#image');
ColorThief.getColor(img)
.then(color => { console.log(color) })
.catch(err => { console.log(err) })
任何解决此问题的帮助表示赞赏。
解决方案
来自https://lokeshdhakar.com/projects/color-thief文档
getColor(图像[,质量])
image - 在浏览器中调用时,此参数需要一个 HTML 图像元素,而不是 URL。在 Node 中运行时,此参数需要图像的路径。
推荐阅读
- python - 函数回调时覆盖列表
- php - 在 FPDF 中设置 While 循环
- javascript - 用户注册时创建空白个人资料
- flutter - Navigator.of(context, rootNavigator: true).push()中的`rootNavigator`有什么用?
- javascript - 不要验证 javascript 中的隐藏字段
- javascript - 导航栏如何使用香草 javascript 进行平滑滚动?
- python - 如何在子进程模块的调用方法中传递密码
- javascript - React JS,一种形式的两个提交按钮
- xamarin - 如何使用 Xamarin 表单从登录页面的 OnAppearing 设置我的应用程序主页 (shell)?
- javascript - d3 年滑块启用步骤之间的区域