A React component for grabbing
A React component for grabbing the color palette from an image. See a Demo
It is based on Lokesh's color-thief.
可以把src/ColorThief.js文件拷贝到自己的项目下,直接使用。
Get the dominant color from an imageconst colorThief = new ColorThief() colorThief.getColor(imgDom) //需要在Image onload完成后调用 colorThief.getColorFromUrl(imgUrl).then(...) //异步方法,返回一个Promise Build a color palette from an image
In this example, we build an 8 color palette.
const colorThief = new ColorThief() colorThief.getPalette(imgDom, 8) //需要在Image onload完成后调用 ColorThief Methods
function | returns |
---|---|
getColor(imgDom[, quality]) |
[r, g, b] |
getPalette(imgDom[, colorCount, quality]) |
[ [r, g, b], [r, g, b], ...] |
getColorFromUrl(imgUrl[, quality]) |
[r, g, b] |
getColorAsync(imgUrl[, quality]) |
[r, g, b] |
convertColorRgb(rgbArray) |
"rgb(r, g, b)" |
colorCount
determines the size of the palette, the number of colors returned. If not set, it defaults to 10.
quality
is an optional argument. It needs to be an integer. 1 is the highest quality settings. 10 is the default. There is a trade-off between quality and speed. The bigger the number, the faster the palette generation but the greater the likelihood that colors will be missed.
版权声明:
1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。2、网站不提供资料下载,如需下载请到原作者页面进行下载。