从图像生成css渐变的python库
gradif的Python项目详细描述
从图像生成css渐变的python库。这是叉子 https://github.com/fraser-hemp/gradify。原来的gradify项目只有一个cli 接口。使用这个fork,可以在python代码中将gradify用作库。
安装
安装pypi的最新版本:
pip install gradify
用法
gradify.generate_css(fp,single_color=False,use_color_spread=False)
- fp:文件名(字符串)、pathlib.path对象或文件对象。 文件对象必须实现read()、seek()和tell()方法, 并以二进制模式打开。
- single_color:只产生单一、统一的背景色- 这要快得多,而且所有浏览器都支持
- use_color_spread:此标志将给出具有最少 分配方向时在图像上分散最高优先级 (与最主要的颜色相反)。这项功能提高了整体精度, 然而,增加复杂性,在独特的情况下,它产生反直觉的结果
示例:
importgradifycss=gradify.generate_css('sample.png')
高级用法
您可以使用Gradify类进行高级使用。
fromgradifyimportGradify# simple usageg=Gradify('sample.png',single_color=False,use_color_spread=False)css=g.generate_css()# advanced usageg=Gradify('sample.png',single_color=False,use_color_spread=False,black_sensitivity=4.3,white_sensitivity=3,num_colors=4,resize=55,uniformness=7,use_prefixes=False)css=g.generate_css()
默认参数产生良好的结果。
来自原始回购:
The only suggestion is increasing the uniformness (by lowering it’s value). It can improve the general case, improve speed, but decrease the upper limits of accuracy. Increasing sensitivity to black will do the same.
学分
非常感谢Fraser Hemphill编写原始的gradify项目。
许可证
麻省理工学院