diff options
| author | dylan <dylan.araps@gmail.com> | 2020-01-23 10:38:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-23 10:38:33 +0200 |
| commit | c1d90676f9074cf4131f8cb94aeb2344d6fc8ecc (patch) | |
| tree | 63e7fe384b10449fd893b5a2da3e90199df21dae /pywal/backends/colorz.py | |
| parent | 7ecc2ffd39d1c01639da666dd4dbe0aa4789f85c (diff) | |
| parent | 3537e8cc8f2af2051dd695ef1ca7247e76e0f74f (diff) | |
Merge branch 'master' into add-vs-code-support
Diffstat (limited to 'pywal/backends/colorz.py')
| -rw-r--r-- | pywal/backends/colorz.py | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/pywal/backends/colorz.py b/pywal/backends/colorz.py index 642ff6b..b789a3a 100644 --- a/pywal/backends/colorz.py +++ b/pywal/backends/colorz.py @@ -2,36 +2,42 @@ Generate a colorscheme using Colorz. """ import logging -import shutil -import subprocess import sys +try: + import colorz + +except ImportError: + logging.error("colorz wasn't found on your system.") + logging.error("Try another backend. (wal --backend)") + sys.exit(1) + from .. import colors from .. import util def gen_colors(img): """Generate a colorscheme using Colorz.""" - cmd = ["colorz", "-n", "6", "--bold", "0", "--no-preview", "--no-bg-img"] - return subprocess.check_output([*cmd, img]).splitlines() + # pylint: disable=not-callable + raw_colors = colorz.colorz(img, n=6, bold_add=0) + return [util.rgb_to_hex([*color[0]]) for color in raw_colors] def adjust(cols, light): """Create palette.""" - bg = util.blend_color("#555555", cols[1]) - - raw_colors = [bg, *cols, "#FFFFFF", - "#333333", *cols, "#FFFFFF"] + raw_colors = [cols[0], *cols, "#FFFFFF", + "#000000", *cols, "#FFFFFF"] return colors.generic_adjust(raw_colors, light) def get(img, light=False): """Get colorscheme.""" - if not shutil.which("colorz"): - logging.error("Colorz wasn't found on your system.") - logging.error("Try another backend. (wal --backend)") + cols = gen_colors(img) + + if len(cols) < 6: + logging.error("colorz failed to generate enough colors.") + logging.error("Try another backend or another image. (wal --backend)") sys.exit(1) - cols = [col.decode('UTF-8').split()[0] for col in gen_colors(img)] return adjust(cols, light) |
