colorThief.js是一个从图像中获取相关色调的插件

colorThief.js是一个从图像中获取相关色调的插件

colorThief.js是一个非常有用且易于使用的插件,用于从图像中获取调色板。它的画布标签使它发生。如果使用已加载到DOM中的图像,则可以同步检索颜色调色板。

<script type="text/javascript">
    const colorThief = new ColorThief();
    const imgs = document.getElementById('imgs');

    // Make sure image is finished loading
    if (imgs.complete) {
        console.log(colorThief.getColor(imgs));
    } else {
        imgs.addEventListener('load', function() {
            let color = colorThief.getColor(imgs);
            var span = document.getElementById('span');
            span.style.background = "rgb(" +color[0] + "," + color[1]+ "," + color[2] + ")"
        });
    }
</script>

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

github地址https://lokeshdhakar.com/projects/color-thief/

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

网友评论0

程序员在线工具箱