ImageColor Module
The ImageColor
module contains color tables and converters fromCSS3-style color specifiers to RGB tuples. This module is used byPIL.Image.new()
and the ImageDraw
module, amongothers.
Color Names
The ImageColor module supports the following string formats:
- Hexadecimal color specifiers, given as
#rgb
or#rrggbb
. For example,#ff0000
specifies pure red. - RGB functions, given as
rgb(red, green, blue)
where the color values areintegers in the range 0 to 255. Alternatively, the color values can be givenas three percentages (0% to 100%). For example,rgb(255,0,0)
andrgb(100%,0%,0%)
both specify pure red. - Hue-Saturation-Lightness (HSL) functions, given as
hsl(hue, saturation%,
where hue is the color given as an angle between 0 and 360(red=0, green=120, blue=240), saturation is a value between 0% and 100%(gray=0%, full color=100%), and lightness is a value between 0% and 100%(black=0%, normal=50%, white=100%). For example,
lightness%)hsl(0,100%,50%)
is purered. - Hue-Saturation-Value (HSV) functions, given as
hsv(hue, saturation%,
where hue and saturation are the same as HSL, and value is between0% and 100% (black=0%, normal=100%). For example,
value%)hsv(0,100%,100%)
ispure red. This format is also known as Hue-Saturation-Brightness (HSB), andcan be given ashsb(hue, saturation%, brightness%)
, where each of thevalues are used as they are in HSV. - Common HTML color names. The
ImageColor
module provides some140 standard color names, based on the colors supported by the X Windowsystem and most web browsers. color names are case insensitive. For example,red
andRed
both specify pure red.
Functions
PIL.ImageColor.
getrgb
(color)[source]- Convert a color string to an RGB tuple. If the string cannot be parsed,this function raises a
ValueError
exception.
New in version 1.1.4.
PIL.ImageColor.
getcolor
(color, mode)[source]- Same as
getrgb()
, but converts the RGB value to agreyscale value if the mode is not color or a palette image. If the stringcannot be parsed, this function raises aValueError
exception.
New in version 1.1.4.