summaryrefslogtreecommitdiff
path: root/pywal/magic.py
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2017-07-22 22:26:49 +1000
committerDylan Araps <dylan.araps@gmail.com>2017-07-22 22:26:49 +1000
commitde47c1beaaa77ee6f50235daba735ccc98ad608c (patch)
tree03fca45aead0204d0b8619d775077f1046230ba0 /pywal/magic.py
parenta4ea6a4f7addc3ada3c466a763331d793190a342 (diff)
api: Remove wal.py
Diffstat (limited to 'pywal/magic.py')
-rw-r--r--pywal/magic.py93
1 files changed, 0 insertions, 93 deletions
diff --git a/pywal/magic.py b/pywal/magic.py
deleted file mode 100644
index 757fdce..0000000
--- a/pywal/magic.py
+++ /dev/null
@@ -1,93 +0,0 @@
-"""
-Generate a colorscheme using imagemagick.
-"""
-import re
-import shutil
-import subprocess
-
-from pywal import util
-
-
-def imagemagick(color_count, img):
- """Call Imagemagick to generate a scheme."""
- colors = subprocess.Popen(["convert", img, "+dither", "-colors",
- str(color_count), "-unique-colors", "txt:-"],
- stdout=subprocess.PIPE)
-
- return colors.stdout.readlines()
-
-
-def gen_colors(img, color_count):
- """Format the output from imagemagick into a list
- of hex colors."""
- if not shutil.which("convert"):
- print("error: imagemagick not found, exiting...\n"
- "error: wal requires imagemagick to function.")
- exit(1)
-
- raw_colors = imagemagick(color_count, img)
-
- index = 0
- while len(raw_colors) - 1 < color_count:
- index += 1
- raw_colors = imagemagick(color_count + index, img)
-
- print("colors: Imagemagick couldn't generate a", color_count,
- "color palette, trying a larger palette size",
- color_count + index)
-
- if index > 20:
- print("colors: Imagemagick couldn't generate a suitable scheme",
- "for the image. Exiting...")
- quit(1)
-
- # Remove the first element because it isn't a color code.
- del raw_colors[0]
-
- return [re.search("#.{6}", str(col)).group(0) for col in raw_colors]
-
-
-def get_colors(img, cache_dir, color_count, quiet):
- """Get the colorscheme."""
- # _home_dylan_img_jpg.json
- cache_file = cache_dir / "schemes" / \
- img.replace("/", "_").replace(".", "_")
- cache_file = cache_file.with_suffix(".json")
-
- if cache_file.is_file():
- colors = util.read_file_json(cache_file)
- print("colors: Found cached colorscheme.")
-
- else:
- util.msg("wal: Generating a colorscheme...", quiet)
-
- colors = gen_colors(img, color_count)
- colors = sort_colors(img, colors)
-
- util.save_file_json(colors, cache_file)
- util.msg("wal: Generation complete.", quiet)
-
- return colors
-
-
-def sort_colors(img, colors):
- """Sort the generated colors and store them in a dict that
- we will later save in json format."""
- raw_colors = colors[:1] + colors[9:] + colors[8:]
-
- colors = {"wallpaper": img}
-
- colors_special = {}
- colors_special.update({"background": raw_colors[0]})
- colors_special.update({"foreground": raw_colors[15]})
- colors_special.update({"cursor": raw_colors[15]})
-
- colors_hex = {}
- for index, color in enumerate(raw_colors):
- colors_hex.update({f"color{index}": color})
-
- colors_hex["color8"] = util.set_grey(raw_colors)
- colors["special"] = colors_special
- colors["colors"] = colors_hex
-
- return colors