DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 967,911 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
natamacm
natamacm

Posted on

Detect any color with Python

You can detect any color with Python. That can be a color of any object defined as string, like:

fish = WhatColorIsX.new('fish')

What it's doing behind the scenes is use Google Image API.

Installation

You can install the module WhatColorIsX with pip.

$ pip install WhatColorIsX

You may find you need to pip install Pillow as a dependency first, although it will be attempted automatically.

Import to your project

For almost all cases, call the new() factory function, then get the colour value from the color() method:

import WhatColorIsX

brick = WhatColorIsX.new('brick')
brick_color = brick.color()
fish = WhatColorIsX.new('fish')
fish_color_bright = fish.color(bright_hue=True)

If you already have PIL images that you want to process, you can use the same syntax:

from WhatColorIsX import whatcoloris_image
from PIL import Image

img = Image.open('images/cat.jpg')
cat = WhatColorIsX.new(img)
cat_color = cat.color()

Top comments (0)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.