Open In App

Python PIL | ImageColor.getcolor() Method

Last Updated : 12 Dec, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageColor module contains color tables and converters from CSS3-style color specifiers to RGB tuples. This module is used by PIL.Image.Image.new() and the ImageDraw module, among others.
ImageColor.getcolor() Same as getrgb(), but converts the RGB value to a grayscale value if the mode is not color or a palette image. If the string cannot be parsed, this function raises a ValueError exception.
 

Syntax: PIL.ImageColor.getcolor(color, mode)
Parameters: 
color - A color string 
Returns: (graylevel [, alpha]) or (red, green, blue[, alpha])

Python3
 

# importing Image module from PIL package 
from PIL import Image, ImageColor

# using getcolor
im = ImageColor.getcolor("orange", "L")
print(im)

im1 = ImageColor.getcolor("red", "L")
print(im1)

Output:  

173
76


Another Example:- Here used different colors.

Python3
 

# importing Image module from PIL package 
from PIL import Image, ImageColor

# using getcolor
im = ImageColor.getcolor("pink", "L")
print(im)

im1 = ImageColor.getcolor("violet", "L")
print(im1)

Output: 

212
174

Next Article
Article Tags :
Practice Tags :

Similar Reads