Python Imaging Library: ImageColor Module(图像颜色模块)

来源:互联网 发布:131458淘宝买家信官网 编辑:程序博客网 时间:2024/06/14 18:09

Python Imaging Library: ImageColor Module(图像颜色模块)

图像颜色模块(ImageColor Module)支持的字符串格式如下:

  • 十六进制(Hexadecimal )颜色说明符,如“#rgb”或“#rrggbb”。例如,“#ff0000” 表示纯红色。

  • RGB函数,如“rgb(red, green, blue)” ,其中颜色值取值范围为【0-255】的整数。作为另外一种选择,也可以使用百分比(0%-100%)。例如“rgb(255,0,0)”“rgb(100%,0%,0%)” 都表示纯红色。

  • Hue-Saturation-Lightness (HSL)函数,如“hsl(hue, saturation%, lightness%)” ,色度(Hue)取值范围为【0-360】(red=0, green=120, blue=240),饱和度(Saturation)取值范围为【0%-100%】 (gray=0%, full color=100%),亮度(lightness取值范围为【0%-100% (black=0%, normal=50%, white=100%)。例如“hsl(0,100%,50%)”表示纯红色。

  • 通用HTML颜色名称。图像颜色模块(ImageColor Module)支持140种标准颜色名称,包含基于X窗口系统和大多数web浏览器支持的颜色。颜色名称不区分大小写。例如“red” and “Red” 表示纯红色。

函数

getrgb(color) ⇒ (red, green, blue)

(New in 1.1.4) Convert a colour string to an RGB tuple. If the string cannot be parsed, this function raises a ValueError exception.

getcolor(color, mode) ⇒ (red, green, blue) or integer

(New in 1.1.4) Same as getrgb, but converts the RGB value to a greyscale value if the mode is not color or a palette image. If the string cannot be parsed, this function raises a ValueError exception.


阅读全文
0 0
原创粉丝点击