node.jscolor-thief

ColorThief.getColor() TypeError: url.indexOf is not a function


I'm trying to use ColorThief in the node.js environment. When invoking ColorThief.getColor() I get the follwing error:

TypeError: url.indexOf is not a function

The error results from this line of code in the module.

if(url.indexOf('data:image/gif;') 

Here my code:

const ColorThief = require('colorthief');
const img = document.querySelector('#image');
ColorThief.getColor(img)
    .then(color => { console.log(color) })
    .catch(err => { console.log(err) })

Any help solving this issue is appreciated.


Solution

  • From the https://lokeshdhakar.com/projects/color-thief documentation

    getColor(image [, quality])

    image - When called in the browser, this argument expects an HTML image element, not a URL. When run in Node, this argument expects a path to the image.