diff --git a/pywal/backends/__init__.py b/pywal/backends/__init__.py index 99ef00d..d1eb6e7 100644 --- a/pywal/backends/__init__.py +++ b/pywal/backends/__init__.py @@ -11,10 +11,12 @@ Created by Dylan Araps. from . import colorthief from . import colorz +from . import schemer2 from . import wal __all__ = [ "colorthief", "colorz", + "schemer2", "wal", ] diff --git a/pywal/backends/colorthief.py b/pywal/backends/colorthief.py index be8a3f1..7e1eec2 100644 --- a/pywal/backends/colorthief.py +++ b/pywal/backends/colorthief.py @@ -7,7 +7,7 @@ try: from colorthief import ColorThief except ImportError: - print("Error: ColorThief wasn't found on your system.", + print("error: ColorThief wasn't found on your system.", "Try another backend. (wal --backend)") sys.exit(1) diff --git a/pywal/backends/colorz.py b/pywal/backends/colorz.py index 5884e54..776678e 100644 --- a/pywal/backends/colorz.py +++ b/pywal/backends/colorz.py @@ -10,8 +10,8 @@ from .. import util def gen_colors(img): """Generate a colorscheme using Colorz.""" - colorz = ["colorz", "-n", "6", "--bold", "0", "--no-preview"] - return subprocess.check_output([*colorz, img]).splitlines() + cmd = ["colorz", "-n", "6", "--bold", "0", "--no-preview"] + return subprocess.check_output([*cmd, img]).splitlines() def adjust(colors, light): @@ -43,7 +43,7 @@ def adjust(colors, light): def get(img, light=False): """Get colorscheme.""" if not shutil.which("colorz"): - print("Error: Colorz wasn't found on your system.", + print("error: Colorz wasn't found on your system.", "Try another backend. (wal --backend)") sys.exit(1) diff --git a/pywal/backends/schemer2.py b/pywal/backends/schemer2.py new file mode 100644 index 0000000..9523972 --- /dev/null +++ b/pywal/backends/schemer2.py @@ -0,0 +1,52 @@ +""" +Generate a colorscheme using Schemer2. +""" +import shutil +import subprocess +import sys + +from .. import util + + +def gen_colors(img): + """Generate a colorscheme using Colorz.""" + cmd = ["schemer2", "-format", "img::colors", "-minBright", "75", "-in"] + return subprocess.check_output([*cmd, img]).splitlines() + + +def adjust(colors, light): + """Create palette.""" + # Create list with placeholder values. + colors.sort(key=util.rgb_to_yiq) + raw_colors = [*colors[8:], *colors[8:]] + + # Update placeholder values. + if light: + for color in raw_colors: + color = util.saturate_color(color, 0.50) + color = util.darken_color(color, 0.4) + + raw_colors[0] = util.lighten_color(colors[0], 0.9) + raw_colors[7] = util.darken_color(colors[0], 0.75) + raw_colors[8] = util.darken_color(colors[0], 0.25) + raw_colors[15] = raw_colors[7] + + else: + raw_colors[0] = util.darken_color(colors[0], 0.75) + raw_colors[7] = util.lighten_color(colors[0], 0.75) + raw_colors[8] = util.lighten_color(colors[0], 0.25) + raw_colors[15] = raw_colors[7] + + return raw_colors + + +def get(img, light=False): + """Get colorscheme.""" + if not shutil.which("schemer2"): + print("error: Schemer2 wasn't found on your system.", + "Try another backend. (wal --backend)") + sys.exit(1) + + colors = gen_colors(img) + colors = [color.decode('UTF-8') for color in colors] + return adjust(colors, light) diff --git a/pywal/backends/wal.py b/pywal/backends/wal.py index 71cd7e4..678c66c 100644 --- a/pywal/backends/wal.py +++ b/pywal/backends/wal.py @@ -26,7 +26,7 @@ def has_im(): elif shutil.which("convert"): return ["convert"] - print("Error: ImageMagick wasn't found on your system.", + print("error: ImageMagick wasn't found on your system.", "Try another backend. (wal --backend)") sys.exit(1)