diff options
| author | Dylan Araps <dylan.araps@gmail.com> | 2017-06-17 01:48:14 +1000 |
|---|---|---|
| committer | Dylan Araps <dylan.araps@gmail.com> | 2017-06-17 01:48:14 +1000 |
| commit | 3b18f37dddf719a7feb2aa5416b2587d091bf8b3 (patch) | |
| tree | 3aec3886000a1782136d491dff9f9eb99e5158a0 | |
| parent | 5b69a3b029f07b8fae83f418f1271f24de9a39ea (diff) | |
General: Generate scheme
| -rw-r--r-- | wal.py | 42 | ||||
| -rw-r--r-- | | grep -E -o " \#.{6}" | bin | 0 -> 325 bytes |
2 files changed, 39 insertions, 3 deletions
@@ -6,6 +6,9 @@ import argparse import os +import pathlib +import subprocess +import re from pathlib import Path from os.path import expanduser @@ -36,9 +39,42 @@ def get_colors(img): image = Path(img) if image.is_file(): - print("File exists!") - else: - print("File doesn't exist. :(") + colors = [] + + # Create colorscheme dir. + pathlib.Path(cache_dir + "/schemes").mkdir(parents=True, exist_ok=True) + cache_file = cache_dir + "/schemes/" + img.replace('/', '_') + + # Cache the wallpaper name. + wal = open(cache_dir + "/wal", 'w') + wal.write(img) + wal.close() + + # Long-ass imagemagick command. + magic = subprocess.Popen(["convert", img, "+dither", "-colors", + str(color_count), "-unique-colors", "txt:-"], + stdout=subprocess.PIPE,stderr=subprocess.PIPE) + + + # Create a list of hex colors. + for color in magic.stdout: + print(color) + hex = re.search('#.{6}', str(color)) + + if hex: + colors.append(hex.group(0)) + + + # Remove the first element which isn't a color. + del colors[0] + + # Cache the colorscheme. + scheme = open(cache_file, 'w') + + for color in colors: + scheme.write(color + "\n") + + scheme.close() def main(): diff --git a/| grep -E -o " \#.{6}" b/| grep -E -o " \#.{6}" Binary files differnew file mode 100644 index 0000000..75a8318 --- /dev/null +++ b/| grep -E -o " \#.{6}" |
