lokesh / color-thief

Grab the color palette from an image using just Javascript. Works in the browser and in Node.
https://lokeshdhakar.com/projects/color-thief/
MIT License
12.34k stars 1.31k forks source link

Crash with plain white image - .get_color(quality=1) #215

Open LuccaGarcia opened 2 years ago

LuccaGarcia commented 2 years ago

Using ColorThief to return the dominant color of a white image raises an exception

Code: image

Exception happens at line four: image

Image used: white

Other colors do not seam to cause the same error

yankovichv commented 2 years ago

Same problem :(

AyatoKirishima commented 2 years ago

Same problem here ✨

AyatoKirishima commented 2 years ago

A try catch in the js file solved it for me (i pushed the hex code into my array aaaand problem solved)

 try {
        rgbColors = colorThief.getColor(element);
        console.log(rgbColors);
        console.log(rgbColors[0]);
        console.log(rgbColors[1]);
        console.log(rgbColors[2]);

        let result = rgbToHex(rgbColors[0], rgbColors[1], rgbColors[2]);

        console.log("Le résultat en hexa est : " + result); // #0033ff
        colorsArray.push(result);
        console.log(colorsArray);

    } catch (error) {
        console.log(error);
        colorsArray.push("#ffffff");
    }