Skip to main content

Get color of a string via Google image search API

Project description

Python script which takes any string and returns a hex colour string, using Google image search.

master:

Supported Python versions Latest PyPI version Travis CI build status Coveralls coverage status

dev:

Travis CI build status Coveralls coverage status

Installation

$ pip install WhatColorIsX

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

Usage

Input can be any string. Output is a 6-digit hex colour value (#[0-9a-f]{6}).

WhatColorIsX returns an accurate colour value by default. If bright_hue is set to True, it is guaranteed that a bright colour will be returned. If bright_hue is not set, it is likely that some whites, greys or blacks will be returned.

Files can have their colour detected by raising the -f flag and providing the path to the image file (see example below).

The number of images google searched for before giving up and erroring can be specified with --images_to_try and an integer. Default is 10.

The colour module can be used to easily perform further alterations.

Import to your project

from WhatColorIsX import whatcoloris

brick_color = whatcoloris('brick')
fish_color_bright = whatcoloris('fish', bright_hue=True)
my_cat_colour = whatcoloris('my images/cat.jpg', is_file=True)
pineapple_colour = whatcoloris('pineapple', images_to_try=100)

Run from the command line

When installed, the script can be accessed with the whatcoloris command. Usage:

whatcoloris [-h] [-b] [-f] x

positional arguments:
  x                 string to find colour of

optional arguments:
  -h, --help        show this help message and exit
  -b, --bright_hue  return a bright colour; hsl=(x,1.0,0.5)
  -f, --is_file     treat x as a file path to open locally
  --images_to_try IMAGES_TO_TRY
                    number of images to try processing before erroring
$ whatcoloris sky
#769ab8
$ whatcoloris -f images/dog.png
#6c5a47

It can also be called directly:

$ python WhatColorIsX.py grass -b
#65ff00

Errors

If the search does not find a suitable image to process, the WhatColorIsX.InvalidSearchResults exception will be raised. Examples that cause this error include:

from WhatColorIsX import whatcoloris

no_search_string = whatcoloris('')
no_images_returned = whatcoloris('foo', images_to_try=0)

Additional Scripts

These scripts will not be installed automatically, but can be downloaded directly from GitHub if desired

xml

xmlInterface.py allows WhatColorIsX to interface with a correctly formatted XML file. This allows multiple values to be queued for processing. See the xml folder for the script, example input and output XML files, and the command format used to run it. Raise the -h flag for detailed information.

input.xml:

<foo>
    <bar>
        <name>sun</name>
    </bar>
</foo>

command:

$ python xmlInterface.py input.xml output.xml bar name color

output.xml:

<foo>
    <bar>
        <name>sun</name>
        <color>#873107</color>
    </bar>
</foo>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

WhatColorIsX-1.0.1.zip (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

WhatColorIsX-1.0.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file WhatColorIsX-1.0.1.zip.

File metadata

  • Download URL: WhatColorIsX-1.0.1.zip
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for WhatColorIsX-1.0.1.zip
Algorithm Hash digest
SHA256 6e5d6f12e010be987a4dfc75207461fa08205d53bf0c4c84a3cf810eccd3dcdf
MD5 9bab35c28f06b3e4bcde7df880aa6cbe
BLAKE2b-256 e4cef433e946e37563930bbf41739a0ac72a00dcc274b37cde656804ebe20bdc

See more details on using hashes here.

File details

Details for the file WhatColorIsX-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for WhatColorIsX-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 97d4b5e2545606ce73a8936b64ddbf2616ae38426f7ba6b6c297ee496b61fc29
MD5 e14e55a9c9367aab22d98bdd25e828b1
BLAKE2b-256 a3d2ed48da1f63bea065299478486248d077658e45fcdc040bce82d2660d32b7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page