Vibrant.js是一个从图像中提取主色调的插件

Vibrant.js是一个从图像中提取主色调的插件

Vibrant.js是一个从图像中提取主色调的插件,Vibrant是Android支持库中awesome Palette类的一个javascript端口。

<script type="text/javascript">

    img.addEventListener('load', function() {
        var vibrant = new Vibrant(img);
        var swatches = vibrant.swatches()
        for (var swatch in swatches)
            if (swatches.hasOwnProperty(swatch) && swatches[swatch])
            document.getElementById('span'+swatch).style.background = swatches[swatch].getHex();
        console.log(swatch, swatches[swatch].getHex())

        /*
     * Results into:
     * Vibrant #7a4426
     * Muted #7b9eae
     * DarkVibrant #348945
     * DarkMuted #141414
     * LightVibrant #f3ccb4
     */
    });
</script>

查看demo http://editor.bfw.wiki/Editor/Open.html?projectid=15748222447089740088&file=demo3.html

github地址https://github.com/jariz/vibrant.js

立即下载Vibrant.js查看所有js插件

网友评论0

程序员在线工具箱