Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fengsp/color-thief-py
Grabs the dominant color or a representative color palette from an image. Uses Python and Pillow.
https://github.com/fengsp/color-thief-py
Last synced: 1 day ago
JSON representation
Grabs the dominant color or a representative color palette from an image. Uses Python and Pillow.
- Host: GitHub
- URL: https://github.com/fengsp/color-thief-py
- Owner: fengsp
- License: other
- Created: 2015-04-16T08:21:49.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-10-31T07:43:19.000Z (about 2 years ago)
- Last Synced: 2024-12-19T03:05:16.794Z (8 days ago)
- Language: Python
- Homepage: http://lokeshdhakar.com/projects/color-thief/
- Size: 13.7 KB
- Stars: 1,049
- Watchers: 17
- Forks: 125
- Open Issues: 25
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES
- License: LICENSE
Awesome Lists containing this project
README
Color Thief
===========A Python module for grabbing the color palette from an image.
Installation
------------::
$ pip install colorthief
Usage
-----.. code:: python
from colorthief import ColorThief
color_thief = ColorThief('/path/to/imagefile')
# get the dominant color
dominant_color = color_thief.get_color(quality=1)
# build a color palette
palette = color_thief.get_palette(color_count=6)API
---.. code:: python
class ColorThief(object):
def __init__(self, file):
"""Create one color thief for one image.:param file: A filename (string) or a file object. The file object
must implement `read()`, `seek()`, and `tell()` methods,
and be opened in binary mode.
"""
passdef get_color(self, quality=10):
"""Get the dominant color.:param quality: quality settings, 1 is the highest quality, the bigger
the number, the faster a color will be returned but
the greater the likelihood that it will not be the
visually most dominant color
:return tuple: (r, g, b)
"""
passdef get_palette(self, color_count=10, quality=10):
"""Build a color palette. We are using the median cut algorithm to
cluster similar colors.:param color_count: the size of the palette, max number of colors
:param quality: quality settings, 1 is the highest quality, the bigger
the number, the faster the palette generation, but the
greater the likelihood that colors will be missed.
:return list: a list of tuple in the form (r, g, b)
"""
passThanks
------Thanks to Lokesh Dhakar for his `original work
`_.Better
------If you feel anything wrong, feedbacks or pull requests are welcome.