| 1 |
Color Thief |
| 2 |
=========== |
| 3 |
|
| 4 |
A Python module for grabbing the color palette from an image. |
| 5 |
|
| 6 |
.. image:: http://img3.douban.com/view/photo/large/public/p2239120853.jpg |
| 7 |
:width: 400 px |
| 8 |
:align: center |
| 9 |
|
| 10 |
Installation |
| 11 |
------------ |
| 12 |
|
| 13 |
:: |
| 14 |
|
| 15 |
$ pip install colorthief |
| 16 |
|
| 17 |
Usage |
| 18 |
----- |
| 19 |
|
| 20 |
.. code:: python |
| 21 |
|
| 22 |
from colorthief import ColorThief |
| 23 |
|
| 24 |
color_thief = ColorThief('/path/to/imagefile') |
| 25 |
# get the dominant color |
| 26 |
dominant_color = color_thief.get_color(quality=1) |
| 27 |
# build a color palette |
| 28 |
palette = color_thief.get_palette(color_count=6) |
| 29 |
|
| 30 |
API |
| 31 |
--- |
| 32 |
|
| 33 |
.. code:: python |
| 34 |
|
| 35 |
class ColorThief(object): |
| 36 |
def __init__(self, file): |
| 37 |
"""Create one color thief for one image. |
| 38 |
|
| 39 |
:param file: A filename (string) or a file object. The file object |
| 40 |
must implement `read()`, `seek()`, and `tell()` methods, |
| 41 |
and be opened in binary mode. |
| 42 |
""" |
| 43 |
pass |
| 44 |
|
| 45 |
def get_color(self, quality=10): |
| 46 |
"""Get the dominant color. |
| 47 |
|
| 48 |
:param quality: quality settings, 1 is the highest quality, the bigger |
| 49 |
the number, the faster a color will be returned but |
| 50 |
the greater the likelihood that it will not be the |
| 51 |
visually most dominant color |
| 52 |
:return tuple: (r, g, b) |
| 53 |
""" |
| 54 |
pass |
| 55 |
|
| 56 |
def get_palette(self, color_count=10, quality=10): |
| 57 |
"""Build a color palette. We are using the median cut algorithm to |
| 58 |
cluster similar colors. |
| 59 |
|
| 60 |
:param color_count: the size of the palette, max number of colors |
| 61 |
:param quality: quality settings, 1 is the highest quality, the bigger |
| 62 |
the number, the faster the palette generation, but the |
| 63 |
greater the likelihood that colors will be missed. |
| 64 |
:return list: a list of tuple in the form (r, g, b) |
| 65 |
""" |
| 66 |
pass |
| 67 |
|
| 68 |
Thanks |
| 69 |
------ |
| 70 |
|
| 71 |
Thanks to Lokesh Dhakar for his `original work |
| 72 |
<https://github.com/lokesh/color-thief/>`_. |
| 73 |
|
| 74 |
Better |
| 75 |
------ |
| 76 |
|
| 77 |
If you feel anything wrong, feedbacks or pull requests are welcome. |