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

Use .webp files with color-thief #183

Open rmgreenstreet opened 4 years ago

rmgreenstreet commented 4 years ago

Spent a few hours trying to figure out why I always got the error "Image given has not completed loading" and it turns out that the package only works with more traditional image formats like .jpg and .png

This may be a fringe request, but it would be cool if this could work with .webp as well.

If not, it would be nice if the documentation A) Listed more prominently on the NPM/Github readme, and B) Explicitly listed the file types supported.

CypElf commented 3 years ago

+1, webp images support would be great to add.

papattes commented 2 years ago

Yup! It would be cool if it was supported.

For my part, I use this ColorThief to extract the dominant colors. So, to solve this error, I create a temporary JPG file on which I apply the ColorThief::getColor method, then I delete the temporary file.

$image = imagecreatefromwebp($filename);
imagejpeg($image, $tmp_directory . '/tmp.jpg', 100);
imagedestroy($image);

$color_rgb = ColorThief::getColor($tmp_directory . '/tmp.jpg');
unlink($tmp_directory . '/tmp.jpg');

it doesn't solve the problem but if it can help someone in the future ^^

alpuysal commented 2 years ago

+1, webp images support would be great to add.

Dudikowski commented 2 years ago

+1, webp images support would be great to add.

PlopTheReal commented 1 year ago

+1

gitnik commented 7 months ago

I think ultimately this hast little to do with this library and more with: https://github.com/scijs/get-pixels

This library hasn't been updated and is unlikely to ever add webp support.

Which has me believe that unless colorthief switches the underlying library, webp will never be supported

gitnik commented 7 months ago

I added WebP to my own fork. I might clean this up later and release it properly. For now, if you quickly want to add webp support add the following to your package.json and run npm i

"overrides": {
  "get-pixels": "git@github.com:gitnik/get-pixels-webp-support.git#a064e683d16fc26d4015882b2058afa359a7d4be"
},

Use at your own risk