javascript 根据图像主色更改背景颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15999909/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change color of background based on image main color?
提问by user2279722
I don't know if this isactually possible but it would be nice if it is! Taaking inspiration from the new iTunes where the background color seems to be set via the (major) color of the artwork image. I'm looking to do something similar with javascript/cs maybe using jQuery, essentially changing the background-color of a div based on an image inside it.
我不知道这是否真的可行,但如果可行就太好了!从新的 iTunes 中获得灵感,其中背景颜色似乎是通过艺术品图像的(主要)颜色设置的。我希望用 javascript/cs 做一些类似的事情,也许使用 jQuery,基本上是根据里面的图像改变 div 的背景颜色。
回答by ndrizza
Here's what you could try out:
您可以尝试以下方法:
https://github.com/lokesh/color-thief
https://github.com/lokesh/color-thief
This library has a pretty cool demo: http://lokeshdhakar.com/projects/color-thief/
这个库有一个很酷的演示:http: //lokeshdhakar.com/projects/color-thief/
Found here: Get average color of image via Javascript
在这里找到:通过 Javascript 获取图像的平均颜色