summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2017-06-17 01:48:14 +1000
committerDylan Araps <dylan.araps@gmail.com>2017-06-17 01:48:14 +1000
commit3b18f37dddf719a7feb2aa5416b2587d091bf8b3 (patch)
tree3aec3886000a1782136d491dff9f9eb99e5158a0
parent5b69a3b029f07b8fae83f418f1271f24de9a39ea (diff)
General: Generate scheme
-rw-r--r--wal.py42
-rw-r--r--| grep -E -o " \#.{6}"bin0 -> 325 bytes
2 files changed, 39 insertions, 3 deletions
diff --git a/wal.py b/wal.py
index af7cdfe..d2dc75f 100644
--- a/wal.py
+++ b/wal.py
@@ -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}"
new file mode 100644
index 0000000..75a8318
--- /dev/null
+++ b/| grep -E -o " \#.{6}"
Binary files differ