WhatColorIsX Module

The WhatColorIsX module provides an object of the same name (lowercase), which can determining the colour of:

  • A string
  • A local file
  • A PIL.Image.Image

The whatcolorisx Class

class WhatColorIsX.whatcolorisx(input, images_to_try=10)

The whatcolorisx object. Can also be created by the new() factory function.

Parameters:
  • input (string) – The search term to pass to Google image search. If given with a .jpg or .png extension, it is treated as a local file path. Will also accept a PIL.Image.Image object.
  • images_to_try (int) – The number of images to try processing before raising InvalidSearchResults
Returns:

An whatcolorisx object.

Raises:

InvalidSearchResults if no valid image is returned by the search

Methods

whatcolorisx.color(bright_hue=False, method='average_color')

Returns the colour of whatcolorisx.img.

If bright_hue is set to True, a bright hue will be returned.

Parameters:
  • bright_hue (bool) – force a bright colour value (saturation = 1.0, luminance = 0.5)
  • method (string) – The helper method that will pick the colour from the image. Options are average_color() or common_color()
Returns:

the guessed colour of the input string in 6-digit hexadecimal format (e.g. #ffffff)

Return type:

string

Helper methods

whatcolorisx.average_color()

Returns the average colour of whatcolorisx.img.

Recommended for most uses.

Returns:RGB value in a three-member tuple
Return type:tuple
whatcolorisx.common_color()

Returns the most common colour of whatcolorisx.img.

Not recommended for complex images which may be over or under-exposed; there is a high chance a black or white color will be returned.

Returns:RGB value in a three-member tuple
Return type:tuple

Attributes

whatcolorisx.input

The initial input to the whatcolorisx object.

whatcolorisx.img

The PIL.Image.Image image generated from input.

Exceptions

exception WhatColorIsX.InvalidSearchResults

Raised if no valid image is returned by Google Search