mirror of
https://github.com/dylanaraps/pywal.git
synced 2024-12-01 20:33:51 +01:00
Image: Random image, select image file.
This commit is contained in:
parent
d4c181fa47
commit
13444e46bb
13
wal
13
wal
@ -115,14 +115,23 @@ def get_image(img):
|
|||||||
if image.is_file():
|
if image.is_file():
|
||||||
wal_img = image
|
wal_img = image
|
||||||
|
|
||||||
|
# Pick a random image from the directory.
|
||||||
elif image.is_dir():
|
elif image.is_dir():
|
||||||
rand = random.choice(os.listdir(image))
|
images = []
|
||||||
rand_img = "%s/%s" % (str(image), rand)
|
file_types = ('*.png', '*.jpg', '*.jpeg', '*.jpe', '*.gif')
|
||||||
|
for files in file_types:
|
||||||
|
images.extend(glob.glob(str(image) + "/" + files))
|
||||||
|
|
||||||
|
rand_img = random.choice(images)
|
||||||
rand_img = pathlib.Path(rand_img)
|
rand_img = pathlib.Path(rand_img)
|
||||||
|
|
||||||
if rand_img.is_file():
|
if rand_img.is_file():
|
||||||
wal_img = rand_img
|
wal_img = rand_img
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("error: No valid image file found.")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
print("image: Using image", wal_img)
|
print("image: Using image", wal_img)
|
||||||
return wal_img
|
return wal_img
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user