mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-06-25 12:01:48 +02:00
colors: Early graphicsmagick support.
This commit is contained in:
parent
b37d70bdbf
commit
feff9c17ba
@ -19,17 +19,30 @@ def imagemagick(color_count, img):
|
|||||||
elif shutil.which("convert"):
|
elif shutil.which("convert"):
|
||||||
magick_command = ["convert"]
|
magick_command = ["convert"]
|
||||||
|
|
||||||
|
elif shutil.which("gm"):
|
||||||
|
magick_command = ["gm", "convert"]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("error: imagemagick not found, exiting...\n"
|
print("error: imagemagick not found, exiting...\n"
|
||||||
"error: wal requires imagemagick to function.")
|
"error: wal requires imagemagick to function.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
colors = subprocess.run([*magick_command, img,
|
magick_command = ["gm", "convert"]
|
||||||
|
|
||||||
|
def magick(magic="-unique-colors"):
|
||||||
|
"""Run Imagemagick."""
|
||||||
|
return subprocess.run([*magick_command, img,
|
||||||
"-resize", "25%", "+dither",
|
"-resize", "25%", "+dither",
|
||||||
"-colors", str(color_count),
|
"-colors", str(color_count),
|
||||||
"-unique-colors", "txt:-"],
|
magic, "txt:-"],
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
if magick_command[0] == "gm":
|
||||||
|
colors = magick("")
|
||||||
|
|
||||||
|
else:
|
||||||
|
colors = magick()
|
||||||
|
|
||||||
return colors.stdout.splitlines()
|
return colors.stdout.splitlines()
|
||||||
|
|
||||||
|
|
||||||
@ -52,6 +65,14 @@ def gen_colors(img, color_count):
|
|||||||
"for the image. Exiting...")
|
"for the image. Exiting...")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
if len(raw_colors) > 30:
|
||||||
|
raw_colors = [re.search("#.{6}", str(col)).group(0)
|
||||||
|
for col in raw_colors]
|
||||||
|
|
||||||
|
seen = set()
|
||||||
|
seen_add = seen.add
|
||||||
|
return [x for x in raw_colors if not (x in seen or seen_add(x))]
|
||||||
|
|
||||||
# Remove the first element because it isn't a color code.
|
# Remove the first element because it isn't a color code.
|
||||||
del raw_colors[0]
|
del raw_colors[0]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user