Python PIL | ImageColor.getrgb() Method

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.getrgb() Convert a color string to an RGB tuple. If the string cannot be parsed, this function raises a ValueError exception.

Syntax: PIL.ImageColor.getrgb(color)



Parameters:
color – A color string

Returns: (red, green, blue[, alpha])

filter_none

edit
close

play_arrow

link
brightness_4
code

   
  
# importing Image module from PIL package 
from PIL import Image, ImageColor
  
# using getrgb
im = ImageColor.getrgb("orange")
print(im)
  
im1 = ImageColor.getrgb("red")
print(im1)

chevron_right


Output:

(255, 165, 0)
(255, 0, 0)

Another Example:– Here used different colors.

filter_none

edit
close

play_arrow

link
brightness_4
code

   
  
# importing Image module from PIL package 
from PIL import Image, ImageColor
  
# using getrgb
im = ImageColor.getrgb("blue")
print(im)
  
im1 = ImageColor.getrgb("yellow")
print(im1)

chevron_right


Output:

(0, 0, 255)
(255, 255, 0)


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.