mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-01-23 22:38:36 +01:00
General: Check if scheme exists
This commit is contained in:
parent
429e3c9f10
commit
23e01e5e8a
46
wal.py
46
wal.py
@ -76,21 +76,10 @@ def get_image(img):
|
|||||||
return rand_img
|
return rand_img
|
||||||
|
|
||||||
|
|
||||||
def get_colors(img):
|
def gen_colors(img):
|
||||||
"""Generate a colorscheme using imagemagick."""
|
"""Generate a color palette using imagemagick."""
|
||||||
colors = []
|
colors = []
|
||||||
|
|
||||||
# Create colorscheme dir.
|
|
||||||
pathlib.Path(CACHE_DIR + "/schemes").mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
# Cache file.
|
|
||||||
cache_file = CACHE_DIR + "/schemes/" + img.replace('/', '_')
|
|
||||||
|
|
||||||
# Cache the wallpaper name.
|
|
||||||
wal = open(CACHE_DIR + "/wal", 'w')
|
|
||||||
wal.write(img + "\n")
|
|
||||||
wal.close()
|
|
||||||
|
|
||||||
# Long-ass imagemagick command.
|
# Long-ass imagemagick command.
|
||||||
magic = subprocess.Popen(["convert", img, "+dither", "-colors",
|
magic = subprocess.Popen(["convert", img, "+dither", "-colors",
|
||||||
str(COLOR_COUNT), "-unique-colors", "txt:-"],
|
str(COLOR_COUNT), "-unique-colors", "txt:-"],
|
||||||
@ -107,17 +96,38 @@ def get_colors(img):
|
|||||||
# Remove the first element, which isn't a color.
|
# Remove the first element, which isn't a color.
|
||||||
del colors[0]
|
del colors[0]
|
||||||
|
|
||||||
# Cache the colorscheme.
|
return colors
|
||||||
scheme = open(cache_file, 'w')
|
|
||||||
for color in colors:
|
|
||||||
scheme.write(color + "\n")
|
def get_colors(img):
|
||||||
scheme.close()
|
"""Generate a colorscheme using imagemagick."""
|
||||||
|
# Cache file.
|
||||||
|
cache_file = Path(CACHE_DIR + "/schemes/" + img.replace('/', '_'))
|
||||||
|
|
||||||
|
if not cache_file.is_file():
|
||||||
|
# Cache the wallpaper name.
|
||||||
|
wal = open(CACHE_DIR + "/wal", 'w')
|
||||||
|
wal.write(img + "\n")
|
||||||
|
wal.close()
|
||||||
|
|
||||||
|
# Generate the colors.
|
||||||
|
colors = gen_colors(img)
|
||||||
|
|
||||||
|
# Cache the colorscheme.
|
||||||
|
scheme = open(cache_file, 'w')
|
||||||
|
for color in colors:
|
||||||
|
scheme.write(color + "\n")
|
||||||
|
scheme.close()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main script function."""
|
"""Main script function."""
|
||||||
args = get_args()
|
args = get_args()
|
||||||
image = str(get_image(args.i))
|
image = str(get_image(args.i))
|
||||||
|
|
||||||
|
# Create colorscheme dir.
|
||||||
|
pathlib.Path(CACHE_DIR + "/schemes").mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
get_colors(image)
|
get_colors(image)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user