我正在寻找一种JavaScript解决方案以从本地图像中获得显性/静音颜色,我尝试了Vibrant.js并使用了示例:
var img = document.createElement('img');
img.setAttribute('src', 'examples/octocat.png')
img.addEventListener('load', function() {
var vibrant = new Vibrant(img);
var swatches = vibrant.swatches()
for (var swatch in swatches)
if (swatches.hasOwnProperty(swatch) && swatches[swatch])
console.log(swatch, swatches[swatch].getHex())
/*
* Results into:
* Vibrant #7a4426
* Muted #7b9eae
* DarkVibrant #348945
* DarkMuted #141414
* LightVibrant #f3ccb4
*/
});
但是,如果该图像未托管在某种类型的服务器上,则此方法不起作用,是否有任何选项可从本地图像获取颜色?