From 2ffd94e938317a0c0375b7dc8313bdaef05d4df4 Mon Sep 17 00:00:00 2001 From: mik8142 Date: Mon, 26 Mar 2018 12:24:47 +0300 Subject: [PATCH] Add ignore_white parametr, it helps get palette with white dominant color when it needed. Also bump version --- colorthief.py | 10 +++++----- setup.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/colorthief.py b/colorthief.py index 0cd7ada..d8bee81 100644 --- a/colorthief.py +++ b/colorthief.py @@ -8,7 +8,7 @@ :copyright: (c) 2015 by Shipeng Feng. :license: BSD, see LICENSE for more details. """ -__version__ = '0.2.1' +__version__ = '0.2.2' import math @@ -38,7 +38,7 @@ def __init__(self, file): """ self.image = Image.open(file) - def get_color(self, quality=10): + def get_color(self, quality=10, ignore_white=True): """Get the dominant color. :param quality: quality settings, 1 is the highest quality, the bigger @@ -47,10 +47,10 @@ def get_color(self, quality=10): visually most dominant color :return tuple: (r, g, b) """ - palette = self.get_palette(5, quality) + palette = self.get_palette(5, quality, ignore_white) return palette[0] - def get_palette(self, color_count=10, quality=10): + def get_palette(self, color_count=10, quality=10, ignore_white=True): """Build a color palette. We are using the median cut algorithm to cluster similar colors. @@ -69,7 +69,7 @@ def get_palette(self, color_count=10, quality=10): r, g, b, a = pixels[i] # If pixel is mostly opaque and not white if a >= 125: - if not (r > 250 and g > 250 and b > 250): + if not (r > 250 and g > 250 and b > 250 and ignore_white): valid_pixels.append((r, g, b)) # Send array to quantize function which clusters values diff --git a/setup.py b/setup.py index 11ca503..4d6d4e1 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ setup( name='colorthief', - version='0.2.1', + version='0.2.2', url='https://github.com/fengsp/color-thief-py', license='BSD', author='Shipeng Feng',