Color Thief 是用于提取图片的主要颜色或者代表性颜色调色板的工具. 其使用是基于 javascript 和 canvas 的.color-thief-py 是基于 Python 和 Pillow 的实现.
color thief利用 Javascript 和 canvas 标签
获取一张图片的主要颜色
var colorThief = new ColorThief();
colorThief.getColor(sourceImage);
getColor(sourceImage[, quality])
returns {r: num, g: num, b: num}
从一张图片中创建调色板
在这个示例中,我们创建一个包含8个颜色的调色板。
var colorThief = new ColorThief();
colorThief.getPalette(sourceImage, 8);
getPalette(sourceImage[, colorCount, quality])
returns [ [num, num, num], [num, num, num], ... ]
color thief特点
Getting started
The Color Thief package includes multiple distribution files to support different environments and build processes. Here is the list of all the files in the /dist folder and what formats they support:
color-thief.js - CommonJS module for use in Node.
color-thief.mjs - ES6 module. For modern browsers as well as Webpack and Rollup.
color-thief.umd.js - UMD module. For simple script tag loading that exposes a global variable or for RequireJS AMD support.
color-thief.min.js - Duplicate of color-thief.umd.js. Kept around to maintain backwards compatibility.
上一篇:W3C代码标准规范是什么