Skip to content
Related Articles

Related Articles

Improve Article

Python PIL | ImageColor.getrgb() Method

  • Last Updated : 02 Aug, 2019

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])






   
  
# 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)

Output:

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

Another Example:– Here used different colors.




   
  
# 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)

Output:

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

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :