I'm trying to fetch the colors in an image using a module 'get-image-colors'. The module works fine.
But when I try to pass the result to a variable 'colorList', I instead get Promise { <pending> }.
Replacing return colors.map(color => color.hex()) with console.log(colors.map(color => color.hex())) prints the colors fine, but I would like to pass the results to another variable 'colorList'.
Could you please help me spot and fix the problem?
const path = require('path');
const getColors = require('get-image-colors'); // Module to get image colors
let fileName = 'color1.png';
const options = {
count: 5,
type: 'image/png'
}
let colorList = getColors(`assets/colorphotos/${fileName}`, options, function (err, colors) {
if (err) throw err
return colors.map(color => color.hex());
});
console.log(colorList);