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.66k stars 1.31k forks source link

The result is different #178

Open Yuki-Zhao opened 5 years ago

Yuki-Zhao commented 5 years ago

the first picture was from the website.( https://www.lokeshdhakar.com/projects/color-thief/) image

the second picture, i download the dist from github. image

i compared two pictures, the result is different. why ?

u3u commented 4 years ago

https://github.com/lokesh/color-thief/blob/1c70277219c7bcfcd5ea4481cdb17136077c4fc1/src/color-thief.js#L89

It seems that it is caused by the wrong number of pixels obtained here. The size here is the actual size displayed by the picture rather than the original size. Therefore, the extracted color will change according to the width of the image container.

Should it be changed to this? @lokesh

const pixelCount = image.naturalWidth * image.naturalHeight;