diff options
Diffstat (limited to 'pywal/backends')
| -rw-r--r-- | pywal/backends/colorthief.py | 2 | ||||
| -rw-r--r-- | pywal/backends/colorz.py | 30 | ||||
| -rw-r--r-- | pywal/backends/wal.py | 21 |
3 files changed, 34 insertions, 19 deletions
diff --git a/pywal/backends/colorthief.py b/pywal/backends/colorthief.py index bcb9e39..aae5bd0 100644 --- a/pywal/backends/colorthief.py +++ b/pywal/backends/colorthief.py @@ -25,7 +25,7 @@ def gen_colors(img): if len(raw_colors) >= 8: break - elif i == 10: + if i == 10: logging.error("ColorThief couldn't generate a suitable palette.") sys.exit(1) 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) diff --git a/pywal/backends/wal.py b/pywal/backends/wal.py index 9d717b5..f05db41 100644 --- a/pywal/backends/wal.py +++ b/pywal/backends/wal.py @@ -24,7 +24,7 @@ def has_im(): if shutil.which("magick"): return ["magick", "convert"] - elif shutil.which("convert"): + if shutil.which("convert"): return ["convert"] logging.error("Imagemagick wasn't found on your system.") @@ -35,12 +35,21 @@ def has_im(): def gen_colors(img): """Format the output from imagemagick into a list of hex colors.""" - raw_colors = imagemagick(20, img, has_im()) + magick_command = has_im() - if len(raw_colors) < 16: - logging.error("Imagemagick couldn't generate a palette.") - logging.error("Try a different image or backend.") - sys.exit(1) + for i in range(0, 20, 1): + raw_colors = imagemagick(16 + i, img, magick_command) + + if len(raw_colors) > 16: + break + + if i == 19: + logging.error("Imagemagick couldn't generate a suitable palette.") + sys.exit(1) + + else: + logging.warning("Imagemagick couldn't generate a palette.") + logging.warning("Trying a larger palette size %s", 16 + i) return [re.search("#.{6}", str(col)).group(0) for col in raw_colors[1:]] |
