0.2.3 • Published 5 years ago
img-color-palette v0.2.3
Color Palette
提取颜色主色调,仅支持浏览器 (Extract image main color, only support browser)
安装 (Install)
yarn add img-color-palette
# or
npm install img-color-palette
用法 (Usage)
import getPalette from 'img-color-palette';
const img = document.getElementById('img-id');
const colors = getPalette(img, 8, {
image: 0.2, // 0.1 - 1
algorithm: 8, // 1 - 8
});
colors.forEach(color => console.log(color));
说明 (Explain)
function getPalette(
img: HTMLImageElement, // 需要解析的图片
length: number, // 返回的颜色的个数
quality: {
image: number; // 图片的质量 0.1 最小, 1 最大
algorithm: number // 算法精度 1 最差, 8 最好,整数
},
): Color[];