看网上好像没什么对这个库的介绍,搬上来备用,提取主题色算是现代UI设计实现中很重要的工具了。
官网
https://lokeshdhakar.com/projects/color-thief/
内含样例和FAQ
这里介绍的是它的Python实现,项目网址在:
https://github.com/fengsp/color-thief-py
pip安装
pip install colorthief
使用
1 2 3 4 5 6 7 8 9 10 11
| from colorthief import ColorThief
color_thief = ColorThief('/path/to/test.jpg')
dominant_color = color_thief.get_color(quality=1) print(dominant_color)
palette = color_thief.get_palette(color_count=3) print(palette)
|
输出类似:
1 2 3 4 5
| #dominant color (193, 185, 174)
#color palette [(190, 183, 172), (42, 40, 38), (133, 108, 74), (91, 76, 66)]
|