diff options
| author | Dylan Araps <dylanaraps@users.noreply.github.com> | 2017-07-28 15:52:27 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-28 15:52:27 +1000 |
| commit | 8a91a67087590d5df163ccbf4ec40fb2057324dd (patch) | |
| tree | 51f543cfaecd8f93cf74db6e36b32c666bf1a70f /pywal | |
| parent | 017547ff0a1dad869133c81d184a4a94f76b8f87 (diff) | |
| parent | 182479b795e0430cc7b30cabc862465468952cc2 (diff) | |
Merge pull request #60 from dylanaraps/dark
colors: Darken bg if contrast is too low.
Diffstat (limited to 'pywal')
| -rw-r--r-- | pywal/colors.py | 4 | ||||
| -rw-r--r-- | pywal/util.py | 16 |
2 files changed, 17 insertions, 3 deletions
diff --git a/pywal/colors.py b/pywal/colors.py index c939215..7e2dbb0 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -54,6 +54,10 @@ def sort_colors(img, colors): we will later save in json format.""" raw_colors = colors[:1] + colors[9:] + colors[8:] + # Darken the background color if it's too light. + if int(raw_colors[0][1]) >= 3: + raw_colors[0] = util.darken_color(raw_colors[0], 0.25) + colors = {"wallpaper": img} colors_special = {} diff --git a/pywal/util.py b/pywal/util.py index 06c0510..2f86811 100644 --- a/pywal/util.py +++ b/pywal/util.py @@ -20,7 +20,8 @@ class Color: @property def rgb(self): """Convert a hex color to rgb.""" - return hex_to_rgb(self.hex_color) + red, green, blue = hex_to_rgb(self.hex_color) + return f"{red},{green},{blue}" @property def xrgba(self): @@ -99,8 +100,7 @@ def create_dir(directory): def hex_to_rgb(color): """Convert a hex color to rgb.""" - red, green, blue = list(bytes.fromhex(color.strip("#"))) - return f"{red},{green},{blue}" + return tuple(bytes.fromhex(color.strip("#"))) def hex_to_xrgba(color): @@ -109,6 +109,16 @@ def hex_to_xrgba(color): return f"{col[1]}{col[2]}/{col[3]}{col[4]}/{col[5]}{col[6]}/ff" +def rgb_to_hex(color): + """Convert an rgb color to hex.""" + return f"#{color[0]:02x}{color[1]:02x}{color[2]:02x}" + + +def darken_color(color, darkness): + """Darken a hex color.""" + return rgb_to_hex([int(col * (1 - darkness)) for col in hex_to_rgb(color)]) + + def disown(*cmd): """Call a system command in the background, disown it and hide it's output.""" |
